On Tue, Mar 12, 2013 at 5:49 AM, Gabriel Cavalcante <
gabriel.cavalcant...@gmail.com> wrote:

> Hello EveryBody,
>
> I'm trying to implement a custom user model, using django 1.5 and the
> example available at:
>
>
> https://docs.djangoproject.com/en/dev/topics/auth/customizing/#a-full-example
>
> For now, I'm able to create a super user based on my custom model only if
> it has none of ForeignKey or M2M modelfields. When I try to use a
> ForeignKey, for example, the following error occurs (obtained trough
> --traceback option of createsuperuser command):
>
> http://dpaste.com/hold/1019886/
>
> In other way,  I can instantiate the class and it has the attribute
> "_state". Additionally, "_state.db" is None.
>
> How can I fix this? I'm doing something wrong?
>
>
You're not doing something wrong per-se -- I think you're just doing
something that isn't exactly compatible with the createsuperuer management
command.

I suspect you'll find that while the createsuperuser management doesn't
work, DsimUser.objects.create_superuser() *will* work as a command issue
from the Python shell.

The problem is that you've created a User model that the createsuperuser
management command can't instantiate. Since client is a required field,
createsuperuser will be asking the user for a value -- but the value needs
to be a foreign key value, and that can't be entered at the keyboard (at
least, not without some post-processing). The error you're seeing is
unusual, but I suspect it's because the internals of Django are turning the
string input into an object that can't be saved as the FK value for the
User object.

This is doubly true for m2m relations -- not only can't you specify an m2m
relation at the keyboard, you can't create an m2m relation until it the
objects involved in the relation have been saved.

This is worth reporting as a bug -- at the very least, we should document
and validate that REQUIRED_FIELDS aren't foreign keys or m2m. A better (but
more complex) solution still would be to allow keyboard entry of FK and m2m
field data (including appropriate hints/search functionality).

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to