1, avoid circular reference: a reference b,b reference a
The way to solve this problem is the app layering, we have designed 4 apps, and now the user action related to the operation models.py can solve the problem:
2, the models of the mailbox verification code and the models of the banner carousel are placed in the users/models.py file (because it has little relationship with others)
"""Import Specification: The first part is the Python module The second part is the third party pour into the module The third part is a custom module""" fromDatetimeImportdatetime fromDjango.dbImportModelsclassEmailverifyrecord (models. Model):"""Email Verification Code models"""Code= Models. Charfield (max_length=20, Verbose_name=u'Verification Code') Email= Models. Emailfield (max_length=50, Verbose_name=u'Email') #There are two types of email verification codes: registering and retrieving forgotten passwordsSend_type = models. Charfield (choices= ('Register', u'Register'),('Forget', u'Retrieve password')), max_length=10) #Verification code Send time #note here that now can not add (), add time is the class compile time, not add is the time of instantiation, here is the need to instantiate timeSend_time = models. Datetimefield (default=DateTime.Now)classMeta:verbose_name= u'Email Verification Code'verbose_name_plural=Verbose_nameclassBanner (models. Model):"""Carousel Diagram Models"""title= Models. Charfield (max_length=100, Verbose_name=u'title') Image= Models. ImageField (upload_to='banner/%y/%m', Verbose_name=u'Carousel Diagram', max_length=100) URL= Models. Urlfield (max_length=200, Verbose_name=u'Access Address') Index= Models. Integerfield (default=100, Verbose_name=u'Carousel Sequence') Add_time= Models. Datetimefield (Default=datetime.now, Verbose_name=u'Add Time') classMeta:verbose_name= u'Carousel Diagram'verbose_name_plural= Verbose_name
users/models.py full code, as follows
"""Import Specification: The first part is the Python module The second part is the third party pour into the module The third part is a custom module""" fromDatetimeImportdatetime fromDjango.dbImportModels#Abstractuser contains the default generated user field for Django fromDjango.contrib.auth.modelsImportAbstractuser#Create your models here.classuserprofile (abstractuser):"""inherit the Abstractuser class, add a database field from a new class of meanings""" #default= ' default is emptyNick_name = models. Charfield (max_length=50, Verbose_name=u'Nickname', default="') #null=true, Blank=true allows users not to fill inBirday = models. Datefield (verbose_name=u'Birthday', Null=true, blank=True)#Choices Property, which provides the selected data, where sex is only male and femaleGender = models. Charfield (max_length=5, choices= ('male', u'male'), ('female'+ R'female')), default='female', Verbose_name=u'Sex')#SexAddress = models. Charfield (max_length=100, Default=u"', Verbose_name=u'Address') Mobile= Models. Charfield (max_length=11, Null=true, Blank=true, Verbose_name=u'Phone number') #upload_to Specify Avatar Upload folderImage = Models. ImageField (upload_to='image/%y/%m', Default=u'Image/default.png', Verbose_name=u'Avatar', max_length=100) classMeta:verbose_name= R'User Information'verbose_name_plural=Verbose_namedef __unicode__(self):"""overloaded functions to enable custom strings to be printed""" returnSelf.usernameclassEmailverifyrecord (models. Model):"""Email Verification Code models"""Code= Models. Charfield (max_length=20, Verbose_name=u'Verification Code') Email= Models. Emailfield (max_length=50, Verbose_name=u'Email') #There are two types of email verification codes: registering and retrieving forgotten passwordsSend_type = models. Charfield (choices= ('Register', u'Register'),('Forget', u'Retrieve password')), max_length=10) #Verification code Send time #note here that now can not add (), add time is the class compile time, not add is the time of instantiation, here is the need to instantiate timeSend_time = models. Datetimefield (default=DateTime.Now)classMeta:verbose_name= u'Email Verification Code'verbose_name_plural=Verbose_nameclassBanner (models. Model):"""Carousel Diagram Models"""title= Models. Charfield (max_length=100, Verbose_name=u'title') Image= Models. ImageField (upload_to='banner/%y/%m', Verbose_name=u'Carousel Diagram', max_length=100) URL= Models. Urlfield (max_length=200, Verbose_name=u'Access Address') Index= Models. Integerfield (default=100, Verbose_name=u'Carousel Sequence') Add_time= Models. Datetimefield (Default=datetime.now, Verbose_name=u'Add Time') classMeta:verbose_name= u'Carousel Diagram'verbose_name_plural= Verbose_name
Django Builds online education platform _day_2: New users app authoring models perfect