django-models

Admin site registering models

I have those models class A(models.Model): name = CharField(max_length=255) class B(models.Model): name = CharField(max_length=255) relation = ForeignKey(A) And I can register like this: admin.site.register(A) admin.site.register(B) In /admin/ page, I can see A and B registered. and "Add B" admin page, will display a c...

Django - Keeping save() based transactions short

As django model save() methods are not lazy, and as keeping transactions short is a general good practice, should saves be preferably deferred to the end of transaction blocks? As an example, would the code sample B hold a transaction open for less time than code sample A below? Code sample A: from django.db import transaction from my...

Django: Before a model is updated, I'd like to "look at" its previous attributes

When an update/create is performed on a Django model (.save()) I would like to be able to "step in" and compare some particular attributes to what they were set to previously (if they previously existed at all). I'm thinking Pre-Save Signals, with a look-up to the original model doing a .objects.get(instance.id), but that feels wastefu...

Filter foreignkey field from the selection of another foreignkey in django-admin?

hi, i have the next models class Region(models.Model): nombre = models.CharField(max_length=25) class Departamento(models.Model): nombre = models.CharField(max_length=25) region = models.ForeignKey(Region) class Municipio(models.Model): nombre = models.CharField(max_length=35) departamento = models.ForeignKey(Depar...

Is it possible to have one 'master' Django website and N satelite websites

I am thinking of a configuration where I have one master website at : www.masterdomain.com and N satelite domains where I can access the satelite domains as follows: www.masterdomain.com/some_url/satetlite1.html www.masterdomain.com/some_url/satetlite2.html ... www.masterdomain.com/some_url/satetliteN.html Is this possible? ...

Django: When extending User, better to use OneToOneField(User) or ForeignKey(User, unique=True)?

I'm finding conflicting information on whether to use OneToOneField(User) or ForeignKey(User, unique=True) when creating a UserProfile model by extending the Django User model. Is it better to use this?: class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) or this?: class UserProfile(models.Model): us...

get_or_create() question

From the official documentation I can't understand what is default parameter. obj, created = Person.objects.get_or_create(first_name='John', last_name='Lennon', defaults={'birthday': date(1940, 10, 9)} Does it mean that it will look for fields which match both John and Lennon parameter and birthday will just insert? ...

Is it possible to assign default display value when ForeignKey is None in Django?

I have ForeignKey in my Django model which can be null. group = models.ForeignKey(Group, null = True, blank = True) In case of null value assigned I want to render some specific text in templates (eg. "No grooup assigned"). I use default filter and it's OK except that I repeat this code in various templates. I am looking for solution...

Inserting language characters in Django

I am following the link http://code.google.com/p/django-multilingual-model/ Basically i am trying to insert hindi characters into mysql db I have created the files in the test directory as in the above said link and using django version 1.1 an dpython version is 2.4.3 I geta error message as the following. from testlanguages import ...

Django - How to reset model fields to their default value?

What would be the most elegant\efficient way to reset all fields of a certain model instance back to their defaults? ...

Is there some method to clen all model in Django (cleen table n database)?

Is there some method to clen all model in Django (cleen table in database)? Sorry i'm not a native english speacker. That why i'm making a lot of misstakes and some time asking question whith i cant undersand by reading official documentation. But I'm doing my best. ...

Django - Reversion and South - How to update past revisions while updating a model?

I would like to preserve past revisions of MyModel instances, while updating and migrating MyModel with south. Is it possible to update the past revisions? Is it necessary to update the revisions on all types of changes to the model? What kind of changes, if any, will force me to erase the revision history no matter what? Is there an el...

Django - How to rename a model field using South?

I would like to change a name of specific fields in a model: class Foo(models.Model): name = models.CharField() rel = models.ForeignKey(Bar) should change to: class Foo(models.Model): full_name = models.CharField() odd_relation = models.ForeignKey(Bar) What's the easiest way to do this using South? ...

Putting 2 fields in the same column in the Django Admin?

Two of my model's fields are "title" and "summary". Right now, "title" is the first field in the ModelAdmin's list_display, which makes it link to the change page. I have some other fields in list_display as well. I'd like to make the admin change list page display "summary" under "title" in plain, unlinked text, in the same column as "...

Change the way the Django Admin sorts integers?

The model has an IntegerField with null=True, blank=True, so it allows the field to have a value of None. When the column is sorted, the Nones are always treated as the lowest values. Is it possible to make Django treat them as the highest values? So when sorted in descending order, instead of: 100 43 7 None It would go: None 100 43 7...

Custom error message in Django admin actions

I've written custom admin actions that basically do QuerySet.update() for certain fields in the model. There are times when these actions shouldn't be allowed to complete -- instead, they should display an error and not do anything. I've tried message_user, but that displays a green checkmark, whereas I'd like it to display the Django ad...

Creating an unlimited forum hierarchy in Django.

Hello, I'm trying to design models for a forum I wish to create in Django. So far I have: class Forum(models.Model): name = models.CharField(max_length=255) slug = models.SlugField(max_length=150) description = models.TextField() def __unicode__(self): return self.name class SubForum(models.Model): paren...

Django-easytree doesn't register in admin.

I've decided to use django-easytree to create a forum hierarchy in django. I downloaded the source via Mercurial from bitbucket. And added the following to a new django app: http://bytebucket.org/fivethreeo/django-easytree/src/7ab11cd55b09/docs/install.rst I added a couple of fields to the model so now it looks like this: class Exampl...

entering different encoding to django model

Hello, django newbie here, I'm trying to insert a foreign language characters into a django model, and get this warning: *Incorrect string value: '\xD7\x90\xD7\x9E\xD7\xAA...' for column 'first_name' at row 1* What should I do to solve this? ...

How to match string with database fields in Django?

I have one database with column - where is datas like 'Very big News' 'News' 'something else' 'New Nes' 'Fresh News' 'Something else' I need match with my database.I Need go through every row in this database and find if i have string field which is inside of this string field. for example if i have field 'News' which is inside. I ...