django - AttributeError: 'Manager' object has no attribute 'get_by_natural_key' -


i'm using django 1.5 on python 3.2.3.

when run python3 manage.py syncdb, builds db tables, & asks email (defined unique instead of username), , when enter that, error --

attributeerror: 'manager' object has no attribute 'get_by_natural_key'

oddly, creates tables anyway, now, i'm confused 'cause don't i'm supposed do. documentation says should create custom user manager, that's says. doesn't give me clue create or how. looked through docs on managers, didn't me figure out. it's vague. keep googling trying find clue need do, i'm going crazy more , more questions instead of answer. here's models.py file:

from django.db import models django.contrib.auth.models import abstractbaseuser  class myusr(abstractbaseuser):     email = models.emailfield(unique=true,db_index=true)     fname = models.charfield(max_length=255,blank=true, null=true)     surname = models.charfield(max_length=255,blank=true, null=true)     pwd_try_count = models.positivesmallintegerfield(blank=true, null=true)     pwd_last_try = models.datetimefield(blank=true, null=true)     resetid = models.charfield(max_length=100,blank=true, null=true)     last_reset = models.datetimefield(blank=true, null=true)     activation_code = models.charfield(max_length=100,blank=true, null=true)     username_field = 'email'     required_fields = ['fname','activation_code'] 

how write custom user manager? put in myusr model method? or i'm supposed do? should doing totally different? i'm not sure of @ point. don't understand. documentation on doesn't seem clear me, leaving lot open interpretation. i'm pretty new django, i've been python several months.

you define custom manager sub-classing baseusermanager , assigning in model objects attribute.

from django.contrib.auth.models import abstractuser, usermanager  class mymgr(baseusermanager):     def create_user(...):         # ...     def create_superuser(...):         # ...   class myusr(abstractbaseuser):     objects = mymgr()      email = models.emailfield(unique=true, db_index=true)     fname = models.charfield(max_length=255, blank=true, null=true)     # ... 

you must define create_user , create_superuser methods baseusermanager. see docs.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -