django-models

How do I save to a field that is specified in a variable?

I want to do something like this: # models.py class Model(models.Model): name_in_my_model = models.CharField(max_length=100) # later fieldname = 'name_in_my_model' # this is what I want to do somehow: obj = Model.objects.get(pk=1) obj.fieldname = 'new name' obj.save() Is this possible? I'm making a reusable application, and ...

Unique field values and ManyToMany relationships

Let's say I have a class structure that is defined below: Class Item(models.Model): ... price = models.IntegerField() upc = models.IntegerField() ... Class Store(models.Model): ... inventory = models.ManyToManyField(Item) ... Basically I want store models to have access to the same inventory. However the v...

Django CharField To String

Hello All, Hopefully a really simple one, possible even stupid! I'm building a tagging system in Django and would like to allow spaces and other characters in the tag name for display but filter them out and use lower case when matching names etc. To that end I have added a field to my Tag model as so: class Tag(models.Model): n...

Django, Import tables as models

I would like to know if it's possible to use django over existing db tables that defines the models. Instead of defining models in order to create db tables ...

Column/field level permissions in Django admin site?

Is it possible to implement column level permissions per user in the Django admin site? Its a small project and I only need two groups of permissions. In the docs I cant find anything out of the box however I was wondering if its possible to create two admin sites and use separate ModelAdmin.exclude or ModelAdmin.fields for each one? I...

Django: Altering model fields from admin views

Hi all, I would like to know how you can change a model's field's parameters, not during model initialisation, but from a model admin. For instance, I would like to make either field "foo" or "bar" optional, according on a get parameter (wondering about the correct solution for the # PSEUDO CODE bit): def add_view(self, request, form_u...

Django is_valid() not working with modelformset_factory

I've created a simple contact form using the modelformset_factory to build the form in the view using the DB model. The issue that I am having is that the is_valid() check before the save() is not working. When I submit the form with empty fields it still passes the is_valid() and attempts to write to the DB. I would like the is_vali...

How to make uniques in Django Models? And also index a column in Django.

This is my simple Django database model. It's for a 5-star rating system. class Rating(models.Model): content = models.OneToOneField(Content, primary_key=True) ip = models.CharField(max_length=200, blank=True) rating = models.IntegerField(default=0) As you can see, it is linked to "Content", which is the table for my docu...

Django ORM: dynamic columns from reference model in resultset

Creating an app to track time off accrual. Users have days and days have types like "Vacation" or "Sick" Models: DayType Name UserDay Date DayType (fk to DayType) Value (+ for accrual, - for day taken) Note Total I'm trying to generate the following resultset expanding the daytypes across columns. Is this possible in the ...

Django: Verbose name of related model not translated

Hi all, I am using ugettext to translate a Category model's verbose_name. This works fine in admin when adding new objects, however, when using Category as in a one-to-many relationship with Post, the Category's verbose_name is neither translated in the list filter nor the change form of Post. How can I correct this? ...

Appengine reference order

I have declared models in AppEngine's models.py: class Post(db.Model): topic = db.ReferenceProperty(Topic, collection_name='posts', verbose_name=_('Topic')) (..) class Topic(db.Model): (..) last_post = db.ReferenceProperty(Post, collection_name='last_topic_post') Problem is ReferenceProperty must have Model class but Topic class is u...

django simple relation

Hi all, I have 2 table in my db Table : users id - primary key username password ... address_id Table : address id - primary key address I want to show this address in User List username , address ( in address table ) How can i do that ? ...

How can I order by GenericForeignKey?

My model is: class Subscription(models.Model): user = models.ForeignKey(User, related_name='subscription', editable=False) following_content_type = models.ForeignKey(ContentType, editable=False) following_id = models.PositiveIntegerField(editable=False) following = generic.GenericForeignKey('following_content_type', 'following_id') cre...

GUI designer for managing Django models

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. ...

App Engine model filtering with Django

hi i am using django app engine patch i have set up a simple model as follows class Intake(db.Model): intake=db.StringProperty(multiline=False, required=True) #@permerlink def get_absolute_url(self): return "/timekeeper/%s/" % self.intake class Meta: db_table = "Intake" verbose_name_plural = "Intake...

Django, Cannot assign None, does not allow null values

i have this models.py import datetime from django.db import models from tinymce import models as tinymce_models from filebrowser.fields import FileBrowseField class ItemWithMedia(models.Model): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) class Actual(ItemWithMedia): publ...

How do I delete an instance of an intermediate model in a Django Many-to-many relationship?

According to an example at http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships I have three models: class User(models.Model): name = models.CharField(max_length=128) class Group(models.Model): name = models.CharField(max_length=128) members = models.ManyToManyField(User, through...

A puzzle concerning Q objects and Foreign Keys

I've got a model like this: class Thing(models.Model): property1 = models.IntegerField() property2 = models.IntegerField() property3 = models.IntegerField() class Subthing(models.Model): subproperty = models.IntegerField() thing = modelsForeignkey(Thing) main = models.BooleanField() I've got a function that is...

Generic relations in Django

Would like to hear your opinion. At the current stage (1.1) would you use generic relations in django or stick to more traditional modeling - given that it's yet impossible to traverse and filter against such relations easily (compared to ForeignKey, ManyToMany, OneToOne relations)? Here is one example - I keep track in the database whe...

Getting Unique Foreign Keys in Django?

Suppose my model looks like this: class Farm(models.Model): name = ... class Tree(models.Model): farm = models.ForeignKey(Farm) ...and I get a QuerySet of Tree objects. How do I determine what farms are represented in that QuerySet? ...