django-models

Unable to migrate using ModelState and ProjectState using of migrations API in Django 3.0.3

回眸只為那壹抹淺笑 提交于 2020-11-28 10:58:00
问题 I am using ProjectState to migrate to a new attributes of a table. I am trying to understand the ModelState and ProjectState using of migrations API in Django 3.0.3. I am unable to migrate to the new state which has new fields. Can someone help me with the ProjectState and ModelState usage of what to apply for new model_definition migration to work? The following code does not migrate to DB but doesnt give any error. I want to migrate from a DB table state to another state and there are some

Unable to migrate using ModelState and ProjectState using of migrations API in Django 3.0.3

主宰稳场 提交于 2020-11-28 10:56:38
问题 I am using ProjectState to migrate to a new attributes of a table. I am trying to understand the ModelState and ProjectState using of migrations API in Django 3.0.3. I am unable to migrate to the new state which has new fields. Can someone help me with the ProjectState and ModelState usage of what to apply for new model_definition migration to work? The following code does not migrate to DB but doesnt give any error. I want to migrate from a DB table state to another state and there are some

Django model - set default charfield in lowercase

天大地大妈咪最大 提交于 2020-11-26 10:24:13
问题 How to set default charfield in lowercase? This is my model: class User(models.Model): username = models.CharField(max_length=100, unique=True) password = models.CharField(max_length=64) name = models.CharField(max_length=200) phone = models.CharField(max_length=20) email = models.CharField(max_length=200) def __init__(self, *args, **kwargs): self.username = self.username.lower() I tried the __init__ but it doesn't work. I want to make the username in lowercase every time new record saved.

Understanding Django GenericForeignKey and GenericRelation

二次信任 提交于 2020-11-24 08:39:28
问题 I'm building vocabulary and have following models: class Word(Model): name = CharField(max_length=75) class EnNoun(Model): word = OneToOneField(Word) class FrNoun(Model): word = ForeignKey(Word) gender = CharField() Same word can be in both EnNoun and FrNoun . Is it possible to fetch result for given word for both EnNoun and FrNoun , using the least number of queries (there will be more similar classes for language and part of speech, like ItAdverb )? How to store translation from one lang to