Suppose I have a Book model containing a foreign key to a Publisher model.
How can I display in the Django admin a column with the number of books published by each publisher, in a way that I can use the built-in sorting?
...
I have a model with data in it defined like this:
class SyncJob(models.Model):
date = models.DateTimeField()
user = models.ForeignKey(User, unique=False)
source = models.CharField(max_length=3, choices=FS_CHOICES)
destination = models.CharField(max_length=3, choices=FS_CHOICES)
options = models.CharField(max_length=10, choices...
i am using django-admin, and i have a model as following. it shows as a dropdown list in the admin. how can i order it by alphabet? instead of default user ID?
user= models.ForeignKey(User)
...
I have a django project with a database table that already contains data. I'd like to change the field name without losing any of the data in that column. My original plan was to simply change the model field name in a way that would not actually alter the name of the db table (using the db_column column parameter):
The original model...
I'm working with content types in feincms. And I want to make a content type that can store filters in the database.
Roughly it would look like this:
from news.models import Entry
class NewsContent(models.Model):
filter = models.CharField()
exclude = models.CharField()
offset = models.IntegerField()
limit = models.Intege...
If I have two classes A and B with a many to many relationship and I want to delete an instance of A, do I need to remove all of its related Bs first or will Django sort that out for me?
I obviously don't want to leave orphaned rows in the join table.
Does it make any difference if the ManyToMany field is declared on class A or B?
Doe...
Hey everyone!
I'm a little stumped here, I can't find what I'm looking for in the Django docs...
What I want, is to be able to override the Save method of an Model. I want it to check for a certain set of conditions - if these conditions are met, it will create the object just fine, but if the conditions are not met, I want to raise an...
I'm sorta having a django / db brainfart.
In words I'm trying to come up with a better way to represent Address objects in my project. I have 5 or 6 different models that have one or more associations to an Address (Billing / Shipping / etc) and I need to allow these addresses to be created/modified/deleted. My first thought was to ...
Is there a way to specify that a model (or app, even) should only ever use one particular database?
I am working with a legacy database that I don't want to change. I have two databases - the 'default' is an sqlite one that could be used for admin etc, and the legacy one. I used inspectdb to create a model for (part of) the legacy datab...
Hello
I have an already existing app with alot of database entries.
class Foo(models.Model):
value = models.TextField(u"Value")
For this I do this:
python manage.py schemamigration myapp --initial
python manage.py migrate myapp
I change the model to such:
class Foo(models.Model):
value = models.TextField(u"Value")
liv...
Is there anything similar to Django data models in ASP.NET MVC where I can easily manipulate my classes and objects and don't worry about SQL realization of it?
...
How should one handle a possible race condition in a model's save() method?
For example, the following example implements a model with an ordered list of related items. When creating a new Item the current list size is used as the its position.
From what I can tell, this can go wrong if multiple Items are created concurrently (will it...
I'm trying to implement User Registration for my Django app. The book I read mentions UserCreationForm but I need more than just name, password, and email address. I could implement my own user object and use ModelForm I think, but then I lose out on some of the django conveniences for authentication. Finally, I read something about U...
I am trying to subclass CharField with a custom unicode method. Basically, I want to be able to call my custom crypto method on the value that is returned by the default model field. I tried the following, but it seems that admin is getting the values some other way. It seems to me that this would be the most pythonic way to implement...
I have a model that picks up the choices defined in CHOICES like this:
CHOICES = (
('1', '1'),
('2', '2'),
('3', '3'),
)
class select(models.Model):
first = models.CharField(max_length=3, choices=CHOICES)
second = models.CharField(max_length=3, choices=CHOICES)
I would like to be able to add, remove or change choices ...
I have a model with a custom property
class RecipeIngredient(models.Model):
recipe = models.ForeignKey(Recipe)
ingredient = models.ForeignKey(Ingredient)
serving_size = models.ForeignKey(ServingSize)
quantity = models.IntegerField()
order = models.IntegerField()
created = models.DateTimeField(auto_now_add = True)...
There is a model:
class DomainPosition(models.Model):
domain = models.ForeignKey(Domain)
keyword = models.ForeignKey(Keyword)
date = models.DateField()
position = models.IntegerField()
class Meta:
ordering = ['domain', 'keyword']
How to get the data for a template? For each domain want to display table (fi...
I have the following (stripped down) code:
# games/models.py
side_choices = [('A', 'Attack'), ('D', 'Defense')]
position_choices = [(0, 'Commander'), (1, 'Knight'), (2, 'Mage'), (3, 'Healer')]
class Game(models.Model):
users = models.ManyToManyField(User, through='GameParticipation)) // User is Django's user
class GameParticipatio...
I'm looking to provide super-user access to entities belonging to a specific country.
eg. Swedish SU can only admin Swedish entities, etc...
However, I'm new to django (taking over an old system) and I need a lifeline.
I'd like to be able to specify a relationship table.
I've already added a userprofile and with that I have a new fi...
I'm getting a KeyError for 'password' when I try to submit my form.
trace:
Request Method: POST
Request URL: http://localhost:8000/register/
Django Version: 1.2.1
Python Version: 2.7.0
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'djangoproject1.authentication']
Installed ...