Error Cannot Import Name Userprofile
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Circular dependency causing ImportError: cannot import name up vote 1 down vote favorite This is the first time I have encountered this. Maybe it's due to bad design. Anyway, I don't know how to fix it. Here are the models that are not playing nicely: talk/models.py from agencies.models import UserProfile class Message(models.Model): text = models.TextField() source = models.ForeignKey(UserProfile, related_name='source') dest = models.ForeignKey(UserProfile, related_name='dest') created = models.DateTimeField(auto_now_add=True) seen = models.BooleanField(default=False) class Meta: ordering = ['created'] agencies/models.py # from talk.models import Message When I uncomment that it says ImportError: cannot import name UserProfile. I really want it though so I can add this property to my UserProfile class... class UserProfile(models.Model): # ... @property def unseen_messages_from(self): pass # :( Any ideas on how to fix this issue? python django model circular-dependency share|improve this question asked Jul 15 '14 at 22:46 broinjc 7912930 So you have Message class that uses UserProfile and you want to have UserProfile that uses Message class, is that right? –Mariatta Jul 15 '14 at 22:50 Yes, I do. Is this impossible? –broinjc Jul 15 '14 at 22:52 The messaging goes 1:M. So for that 1, I want to see m.unseen_messages_from for associated m. If that makes any sense whatsoever. –broinjc Jul 15 '14 at 22:53 add a comment| 1 Answer 1 active oldest votes up vote 3 down vote accepted Django foreign keys allow you to specify models as strings to avoid import issues. In your case you could do
Previous TicketNext Ticket → Opened 9 years ago Closed 9 years ago #4591 closed (invalid) cannot import name User (error retrieving User from django.contrib.auth) Reported by: icsmith12@… Owned by: Adrian Holovaty Component: Contrib apps Version: master Severity: Keywords: Cc: Triage Stage: Unreviewed Has patch: no Needs documentation: no Needs tests: no Patch needs improvement: no Easy pickings: UI/UX: Description I was making an application that included user profiles, and I thought I was done with the first part so I entered an sql command and got this: Ian-Smiths-Computer:~/Sites/matches ismith$ python manage.py sql nest matches.cafe: cannot import name User 1 http://stackoverflow.com/questions/24769423/circular-dependency-causing-importerror-cannot-import-name error found. BEGIN; CREATE TABLE `nest_userprofile` ( `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `website` varchar(200) NOT NULL, `about` longtext NOT NULL, `avatar` varchar(100) NOT NULL, `user_id` integer NOT NULL UNIQUE REFERENCES `auth_user` (`id`) ); COMMIT; Here is what my nest/models.py looks like: from django.db import models from django.contrib.auth.models import User # Create your models here. class UserProfile(models.Model): website = models.URLField() about = https://code.djangoproject.com/ticket/4591 models.TextField() avatar = models.ImageField(upload_to='avatars') user = models.ForeignKey(User, unique=True) I'm using it to extend the User model, but for some reason it cannot connect to it. I then tried to re-SQL another app in my project that hadn't had a problem, and it gave the same error. I even included AUTH_PROFILE_MODULE = 'nest.UserProfile' in my project's settings.py I was thinking maybe I should redownload django, to reset contrib/auth/models.py, just in case it got modified somehow. Oldest first Newest first Threaded Show comments Show property changes Change History (1) comment:1 Changed 9 years ago by Malcolm Tredinnick Needs documentation: unset Needs tests: unset Patch needs improvement: unset Resolution: → invalid Status: new → closed Please post support queries like this to the django-users mailing list. We use Trac only for concrete bug reports (importing the User model should be working, so you probably want to get a bit of help on the mailing list first, before we assume it's a Django bug). Note: See TracTickets for help on using tickets. Download in other formats: Comma-delimited Text Tab-delimited Text RSS Feed Back to Top Django Links Learn Mo
Sign in Pricing Blog Support Search GitHub This repository https://github.com/pennersr/django-allauth/issues/572 Watch 150 Star 2,600 Fork 952 pennersr/django-allauth Code Issues 69 Pull requests 6 Projects 0 Pulse Graphs New issue cannot import name https://groups.google.com/d/topic/django-updates/45mNIajeyr0 BaseSignupForm error #572 Closed luzfcb opened this Issue Mar 18, 2014 · 2 comments Projects None yet Labels None yet error cannot Milestone No milestone Assignees No one assigned 2 participants luzfcb commented Mar 18, 2014 Hello I'm having trouble creating a custom signup form as very briefly described in the documentation. I created a new project using cookiecutter-django I created a new app called myapp error cannot import and put myaap into INSTALED_APPS in settings.py file within the app folder myapp, i created a forms.py file. from allauth.account.forms import BaseSignupForm class SignupForm(BaseSignupForm): def signup(self, request, user): print('#######################') print('here', self.__class__.__name__) print('#######################') put ACCOUNT_SIGNUP_FORM_CLASS = "myapp.forms.SignupForm" into settings.py file After runserver, result in this /home/sutransdev/1envs_virtualenv/sisposto/bin/python2.7 /home/sutransdev/projetos/posto/sisposto/sisposto/manage.py runserver 127.0.0.1:8000 django-configurations version 0.8, using configuration 'Local' Validating models... Unhandled exception in thread started by
von GoogleAnmeldenAusgeblendete FelderNach Gruppen oder Nachrichten suchen