django-models

Django: Models: How can I make the app_label appear in all caps?

Hello - 2 questions... If I manually set my app_label, is there a way to set it to all caps? I am using an acronym for the app name and is a little confusing to not have it in all caps. If I set the app_label on a new project, were I have no users or data, what kind of issues should I look when setting up user permissions and database...

Letting users to choose what type of content they want to input

Hi, This is my first post here, and I'd like to describe what I want to do as specific as possible. I'd like to make a model that is 'selectable.' for example, class SimpleModel(models.Model): property = models.CharField(max_length=255) value = GeneralField() GeneralField can be "CharField", "URLField", "TextField" so that ...

django - 404 page displayed for dev web server (http://127.0.0.1:8000/)

I am familiarizing my self with django. I have succesfully installed and tested a demo site. I now want to switch on the admin module, to see what happens. This is the steps I took (granted, some were unnecessary, but I just wanted to make sure I was starting from a clean slate): Edited mysite/settings.py to enable admin Edited mysit...

Django proxy model and ForeignKey

How to make entry.category to be instance of CategoryProxy? See code for details: class Category(models.Model): pass class Entry(models.Model): category = models.ForeignKey(Category) class EntryProxy(Entry): class Meta: proxy = True class CategoryProxy(Category): class Meta: proxy = True entry = EntryProx...

multiple model filtering in django views

I'm trying to get a query from a specific model. I'm having trouble getting it to filter the data correctly. I've already fixed one bug where it was returning other users data but now its returning duplicates of one row of data in the model. events = Event.objects.filter(club=user.get_profile().main_club) | Event.objects.filter(invclu...

Django: Please help with this queryset

I have a Django model, shown below, that I use to keep track of which ip addresses visit my site and when. class Visit(models.Model): created = models.DateTimeField(default=datetime.utcnow) ip = models.IPAddressField(editable=False) I'd like to write a method on this model that returns the number of days i...

In Django how to create references to different models & being agnostic about what model it is?

I am relatively new to Django/Pinax & I am faced with this peculiar situation. Say I have a model "Vehicle". Now each instance of "Vehicle" has some attributes pertaining to the "vehicle" but it also has a reference to instance of one of automobiles class, where "automobiles" can be one of the many models like "car", "boat", "plane" etc...

getting @permalink decrator to work with django generic views?

Hey guys, Maybe i am missing something, but according to the django docs (1.2), i have setup my URLS, models exactly as specified to ensure i am not hard-coding urls returned for get_absolute_url. Here's what i have: in urls.py urlpatterns = patterns('django.views.generic.list_detail', url(r'^$','object_list', { 'que...

Access Model Data from Django Base Template

I have a model Category, and I want its objects to always be displayed in a navigation menu in my base.html template (which all of my other templates extend). I want to learn best-practices so would like to know what the correct/accepted way of providing this data to the template is. ...

Want to restrict choices to a subset of rows

I'm working on a video management application where each video clip is associated with a single program-name and a single category-name, but programs and categories can be associated with multiple different videos. (This part is straight forward.) What's different is that the choices for category-names vary on a per program basis. For ...

Django model defining list of URLFields

I'm pretty new to relational databases and this may be why I'm having this problem but I have a model - Post. I want it to have variable number of URLs, however Django only seems to have the OneToManyField which requires a model (not a field - which URLField is). ...

Is it possible to instruct Django to save a model instance to a particular table based on its fields?

I'm attempting to construct a Django application that models an existing set of tables. These tables all have the same fields, plus custom fields per table. What I'm wanting to do is model this structure, and have records save to a particular table based on what table model they are attached to. These tables can be created quite often,...

Django ORM: count a subset of related items

I am looking to find a way to annotate a queryset with the counts of a subset of related items. Below is a subset of my models: class Person(models.Model): Name = models.CharField(max_length = 255) PracticeAttended = models.ManyToManyField('Practice', through = 'PracticeRecord') cl...

Django admin site: how to include conditional fields?

Hello, I wonder if is it possible to add some conditional fields in django. Say I have a category model which has an ID, name and description fields. What I would like is to add a many-to-many field in my Product model that links it with the Category ID model... and as a helping reference show what the name of that Category would be. I k...

Django Monthly/quartarly grouping of DateField() data

I've got a django model which contains, among other things, a DateField() attribute: class Table(): date = models.DateField() value = models.FloatField() I'm writing a view that groups this data by week, month Quarter and year. I've hardcoded a calculation that gets my monthly value simply enough - by adding up all the values ...

What are the advantages of using ForeignKey in Django?

This is an extremely naive question. As you can tell, it comes from someone who doesn't know much about either databases or Django. What are the advantages of using ForeignKeys in Django? Maybe an example will help me understand better. I have tables like this already: City: id = IntegerField() # e.g. 15 name = CharField() # ...

django heterogeneous queryset proxy models

Howdy, I am trying to figure out how to use proxy classes in Django. I want to receive a queryset where each object belongs to a proxy class of a common super class so that I can run custom sub-classed methods with the same name and my controller logic doesn't need to know or care about which kind of Proxy model it is working with. One ...

Django - ManyToManyField in a model, setting it to null?

I have a django model (A) which has a ManyToManyField (types) to another model (B). Conceptually the field in A is an 'optionally limit this object to these values'. I have set blank=null and null=True on the ManyToManyField. I have created an object from this model, and set types to some values. All is good. I want to set it to 'null',...

Django admin site: how to compute field from multiple fields value?

I am wondering if is there a way to compute a field in the admin site based on a concatenation of multiple fields. Basically I have a Product model with different fields associated to various attributes (colour, size, length etc). I would like to compute the code value to be a concatenation of the values of the various attribute field...

How do you display only specific variable information within a django-template ?

For example If I have the following models, views and code in a template... class news(models.Model): type = models.ForeignKey(----) (charfield) title = models.CharField(max_length=100) published = models.DateTimeField(default=datetime.now) summary = models.CharField(max_length=200) def ----(): items = news.objects...