django-models

Django custom user field clashes with AbstractBaseUser

守給你的承諾、 提交于 2019-12-30 11:41:47
问题 I am building a Django project from an existing database. The database is being used by other systems, so I cannot change its schema. This is my current custom User model: class Users(AbstractBaseUser): id_user = models.IntegerField(primary_key=True) role = models.IntegerField() username = models.CharField(max_length=50, unique=True) last_login_date = models.DateTimeField() AbstractBaseUser needs a column named last_login , while current database table has last_login_date column which serves

Django - objects.values() and prefetch_related() in same query

我们两清 提交于 2019-12-30 10:37:44
问题 I have Book, Profile, Book_stat model as below. I am trying to minimize the fields from Book model and prefetch_related method to get the data from Book_stat model. models.py class Book(models.Model): title = models.CharField(max_length=200) image = models.FileField(upload_to="mp/", blank=True) def __str__(self): return self.title class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) full_name = models.CharField(max_length=150) def __str__(self): return self

django 1.5 extend the default User model or substitute it

泪湿孤枕 提交于 2019-12-30 10:24:07
问题 Env: Django 1.5.1 + Django CMS 2.4.1 + Zinnia latest + my custom apps + custom Django CMS plugin Basically I can extend the default Django (1.5.X) User model like Django Ribbit Tutorial on NetTuts+ or Substitute a completely customized model like Django Dev doc or Django2Scoops example in the paragraph: "Dealing With the User Model" To test I decided for Subclass AbstractUser From Django2Scoops book:"Choose this option if you like Django’s User model fields the way they are, but need extra .

Django empty field fallback

泄露秘密 提交于 2019-12-30 10:06:18
问题 I have a model that holds user address. This model has to have first_name and last_name fields since one would like to set address to a recipient (like his company etc.). What I'm trying to achieve is: if the fist_name/last_name field in the address is filled - return simply that field if the fist_name/last_name field in the address is empty - fetch corrresponding field data from a foreignkey pointing to a proper django.auth.models.User I'd like this to be treated as normal django field that

Django - Foreign Key must be an instance

元气小坏坏 提交于 2019-12-30 09:05:56
问题 I've a model from django.contrib.auth.models import User class ModelA(models.Model): phone = models.CharField(max_length=20) user = models.ForeignKey(User) I need to insert the data into this model. I've an endpoint hosted which provides me the following data {'phone':XXXXXXXX, 'user_id':123} . Now when I insert the data into this model like obj = ModelA.objects.create(phone=data['phone'], user = data['user_id] It throws an error saying Cannot assign "u'123'": "ModelA.user" must be a "User"

GUI designer for managing Django models

删除回忆录丶 提交于 2019-12-30 08:59:08
问题 Is there a GUI tool using which I can design new Django models graphically? For example, drawing lines between fields in different models to indicate a foreign key. Modifying existing models graphically would also be nice. 回答1: uml-to-django might be of interest to you, though I can't personally vouch for it. 回答2: Another suggestion is found in Django Builder, you can define a model and the builder will get all your program needs such as views, serializers, urls, tests, admins, forms, and

Google app engine ReferenceProperty relationships

▼魔方 西西 提交于 2019-12-30 07:40:59
问题 I'm trying to get my models related using ReferenceProperty, but not have a huge amount of luck. I have 3 levels: Group, Topic, then Pros, and Cons. As in a Group houses many topics, and within each topic could be many Pros and Cons. I am able to store new Groups nice and fine, but I don't have any idea how to store topics underneath these groups. I want to link from a page with a link "New topic" underneath each group, that takes them to a simple form (1 field for now). Obviously the URL

How to switch the direction of a Django OneToOneField?

旧街凉风 提交于 2019-12-30 06:48:52
问题 I currently have a couple of models set up like this: from django.db import models class Child(models.Model): child_name = models.CharField(max_length=200) class Parent(models.Model): parent_name = models.CharField(max_length=200) child = models.OneToOneField(Child, null=True, blank=True) Unfortunately this is wrong, because I want a delete on the parent to cascade to the child and not vice-versa, so I really should have them set up like this: class Parent(models.Model): parent_name = models

How to switch the direction of a Django OneToOneField?

孤街醉人 提交于 2019-12-30 06:48:18
问题 I currently have a couple of models set up like this: from django.db import models class Child(models.Model): child_name = models.CharField(max_length=200) class Parent(models.Model): parent_name = models.CharField(max_length=200) child = models.OneToOneField(Child, null=True, blank=True) Unfortunately this is wrong, because I want a delete on the parent to cascade to the child and not vice-versa, so I really should have them set up like this: class Parent(models.Model): parent_name = models

How to switch the direction of a Django OneToOneField?

大憨熊 提交于 2019-12-30 06:48:15
问题 I currently have a couple of models set up like this: from django.db import models class Child(models.Model): child_name = models.CharField(max_length=200) class Parent(models.Model): parent_name = models.CharField(max_length=200) child = models.OneToOneField(Child, null=True, blank=True) Unfortunately this is wrong, because I want a delete on the parent to cascade to the child and not vice-versa, so I really should have them set up like this: class Parent(models.Model): parent_name = models