django-models

Comparing two db designs for internal messaging

烂漫一生 提交于 2020-01-13 11:27:38
问题 Which of the following db design would be preferable for an internal messaging system. Three tables: MessageThread(models.Model): - subject - timestamp - creator Message(models.Model): - thread (pk) - content - timestamp - sender MessageRecipient - message_id (pk) - recipient (pk) - status (read, unread, deleted) Two tables: Message - thread_id - subject - content - timestamp - sender (fk) MessageRecipient - message_id (fk) - recipient (fk) - status (read, unread, deleted) What would be the

Select_related() backwards relation - auto model population

大兔子大兔子 提交于 2020-01-13 10:54:27
问题 If I have the following model: class Contact(models.Model) name = models.CharField(max_length=100) ... class ContactAddress(models.Model) line1 = models.CharField(max_length=100) line2 = models.CharField(max_length=100) ... contact = models.ForeignKey(Contact) I now want to grab all Contacts and for the address to be auto populated. What would be the best way to do this? The only way I have found so far is to filter out the Contacts I want and loop around each contact and assign this to

How can I customize the display of a model using contenttypes in the admin?

孤人 提交于 2020-01-13 09:52:11
问题 I have these models: class App(models.Model): name = models.CharField(max_length=100) class ProjectA(models.Model): name = models.CharField(max_length=100) app = models.ForeignKey(App) class ProjectB(ProjectA): pass class Attachment(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() project = generic.GenericForeignKey("content_type","object_id") file = models.FileField(upload_to=".") I'm registering all the models for the admin, and I'm

Django DateTimeField() and timezone.now()

你离开我真会死。 提交于 2020-01-13 09:07:33
问题 OK, weird time zone issues when I'm running function tests. Django 1.4, Python 2.7. Are milliseconds truncated in DateTimeField() on MySQL? That's the only theory I've got. model file from django.db import models from django.utils import timezone class Search(models.Model): query = models.CharField(max_length=200, null=True) query_date = models.DateTimeField(null=True) test.py from django.test import TestCase from django.utils import timezone from search.models import Search class

django get_or_create return error: 'tuple' object has no attribute

妖精的绣舞 提交于 2020-01-13 07:43:08
问题 I am new to django and I am trying to use get_or_create model function but I get an error even I have the attribute in my model AttributeError at /professor/adicionar-compromisso 'tuple' object has no attribute 'dias' Request Method: POST Request URL: http://localhost:8000/professor/adicionar-compromisso Django Version: 1.4.1 Exception Type: AttributeError Exception Value: 'tuple' object has no attribute 'dias' Exception Location: c:\htdocs\rpv\GerenDisponibilidade\professor\models.py in

Django Cart and Item Model - getting quantity to update

拥有回忆 提交于 2020-01-13 07:25:21
问题 I am working on a Django cart application. I have two models Cart and Item. I am trying to get the quantity to update when an Item is added to the basket but cant get the views to work properly. I am having problems getting item_obj assignment to work - do I need to do anything with the model manager here? Any help is really appreciated. Models.py class Cart(models.Model): user = models.ForeignKey(User, null=True, blank=True) products = models.ManyToManyField(Product, blank=True) total =

Django Cart and Item Model - getting quantity to update

ぐ巨炮叔叔 提交于 2020-01-13 07:24:13
问题 I am working on a Django cart application. I have two models Cart and Item. I am trying to get the quantity to update when an Item is added to the basket but cant get the views to work properly. I am having problems getting item_obj assignment to work - do I need to do anything with the model manager here? Any help is really appreciated. Models.py class Cart(models.Model): user = models.ForeignKey(User, null=True, blank=True) products = models.ManyToManyField(Product, blank=True) total =

Designing a database for a user/points system? (in Django)

烈酒焚心 提交于 2020-01-13 07:17:30
问题 First of all, sorry if this isn't an appropriate question for StackOverflow. I've tried to make it as generalisable as possible. I want to create a database (MySQL, site running Django) that has users, who can be allocated a certain number of points for various types of action - it's a collaborative game. My requirements are to obtain: the number of points a user has the user's ranking compared to all other users and the overall leaderboard (i.e. all users ranked in order of points) This is

How to insert NULL in database using Django

送分小仙女□ 提交于 2020-01-13 07:02:20
问题 I have a problem inserting NULL in Django. I mean i don't know how to do this. I have function, lets call it find_position , then i have field in model like position (IntegerField, null=True, blank=True). This function inspect some html code, and if it match with some regex, it returns integer, but if it doesn't find - have to return NULL or None or something that I can put in database. def find_position(self, to_find, something): ... if re.search(to_find, something): return i + (page * 10) +

Django admin site: How does the Add User page work (more fields on edit)?

南笙酒味 提交于 2020-01-13 07:00:28
问题 I was wondering how they made it possible to display more fields in the User page of the Django admin site. If you create a new User you only have some basic fields to fill in, but if you reopen that user (edit mode) then you see a lot more fields to fill in. I'm trying to achieve the same, I had a look at the add_form.html template but I can't really get my head around it. I guess I'm looking for a way of specifying different fields = [] sets based on the edit status of the document. Thanks!