django-models

Relationships in Django Admin

I get really confused with many-to-many database relationships, so can some one please clarify how I would achieve this? I need a table of "Tags" (as in tag words) and a table for "Entries", such at many "Entries" could correspond to many Tag words. Right now I have my models like this: # models.py class Tags(models.Model): tag ...

Memcache db models to make search more efficient

Hello, I need to set up some kind of e-store with search functionality. For every search request I got to query structure like this: product: -name -tags --tag -ingredients --ingredient ---tags ----tag ---options ----option -----option details -variants --variant ---tags ----tag ---options ----option measure ----value ---price Now im...

Loading and saving data from m2m relationships in Textarea widgets with ModelForm

I have a Model that looks something like this: class Business(models.Model): name = models.CharField('business name', max_length=100) # ... some other fields emails = models.ManyToManyField(Email, null=True) phone_numbers = models.ManyToManyField(PhoneNumber, null=True) urls = models.ManyToManyField(URL, null=True) ...

Loose coupling of apps & model inheritance

Hi there, I have a design question concerning Django. I am not quite sure how to apply the principle of loose coupling of apps to this specific problem: I have an order-app that manages orders (in an online shop). Within this order-app I have two classes: class Order(models.Model): # some fields def order_payment_complete(self)...

database design for multiple similar content types

I've worked on multiple sites recently with similar content types but haven't gotten the design I'm looking to achieve. I have multiple types of content article, interview, video, gallery, blog, etc. All of these models have very similar properties (title, slug, body, pub_date, etc). And since I'm using django and the admin, almost all ...

Django saving objects - works, but values of objects seem to be cached until I restart server

I'm writing an app for tagging photos. One of the views handles adding new tags and without boilerplate for POST/GET and handling field errors it does this: tagName = request.cleaned_attributes['tagName'] t = Tag.objects.create(name = tagName) t.save() Now in a view for another request to retrieve all tags I have: tags = Tag.objects....

Is it possible to subclass a django model used in a many2many though relation?

Hi there, I was wondering whether it was possible to subclass a model used as the intermediate model in a M2M relation - and then display it through the usual ModelInline procedure... The code will explain it better (in models.py): from django.db import models from django.contrib import admin #the many2many_through model first class...

Django ModelForm CheckBox Widget

I'm currently have an issue, and likely overlooking something very trivial. I have a field in my model that should allow for multiple choices via a checkbox form (it doesn't have to be a checkbox in the admin screen, just in the form area that the end-user will see). Currently I have the field setup like so: # Type of Media MEDIA_CHOICE...

Really long query

How do u do long query? Is there way to optimize it? I would do complicated and long query: all_accepted_parts = acceptedFragment.objects.filter(fragmentID = fragment.objects.filter(categories = fragmentCategory.objects.filter(id=1))) but it doesn't work, i get: Error binding parameter 0 - probably unsupported type. I will be than...

models.py with ManyToMany and progmatically adding data via a shell script

Hi Guys, First post to stackoverflow I did do a search and came up dry. I also own the django book (Forcier,Bissex,Chun) and they don't explain how to do this. In short I can't figure out how to progmatically add a data via a python shell script to the ManyToMay model.. from django.db import models from django.contrib import adm...

Using the "extra fields " from django many-to-many relationships with extra fields.

Django documents give this example of associating extra data with a M2M relationship. Although that is straight forward, now that I am trying to make use of the extra data in my views it is feeling very clumsy (which typically means "I'm doing it wrong"). For example, using the models defined in the linked document above I can do the ...

Django,prepopulated_fields

Hi guys, i want to know if prepopulated_field is available outside of the ModelAdmin? I want to make a slugfield where the value comes from the field title. Regards, Asinox ...

django auto entry generation

Hello, I am trying to make an automated database entry generation with Django, whenever I trigger it to happen. For instance, assume I have a such model: class status_entry(models.Model): name = models.TextField() date = models.DateField() status = models.BooleanField() and I have several entries to the model such as: 1 ...

How To Clone/Mutate A Model In Django Without Subclassing

'Ello, all. I'm trying to create a model in Django based on - but not subclassing or having a DB relation to - another model. My original model looks something like this: it stores some data with a date/time stamp. class Entry(Model): data1 = FloatField() data2 = FloatField() entered = DateTimeField() I'd also like ...

Is there an autoincrement-per-user field in Django?

I was wondering if there is already a way to create a separate autoincrement-ID-per-user field in Django? Basically, I'm storing many related models and I need the IDs generated to be autoincrement per user. I don't want to change how id works, just need a new field that I can add which is unique=True per user. Any suggestions (other ...

converting django ForeignKey to a usable directory name

Hello, I'm working on a django app where the user will be able to upload documents of various kinds. The relevant part of my models.py is this: class Materials(models.Model): id = models.AutoField(primary_key=True) id_presentations = models.ForeignKey(Presentations, db_column='id_Presentations', related_name = "materials_id_pre...

Is a many-to-many relationship with extra fields the right tool for my job?

Previously had a go at asking a more specific version of this question, but had trouble articulating what my question was. On reflection that made me doubt if my chosen solution was correct for the problem, so this time I will explain the problem and ask if a) I am on the right track and b) if there is a way around my current brick wall....

Django ORM Query

If there are models as below: class Donation(models.Model): user = FKey(User) project = FKey(Project) ... class Campaign(models.Model): user = Fkey(User) project = FKey(Project) ... class Project(models.Model) ... What is the simplest django ORM query to find a list of all projects that a give...

Ordering a django change list page via jQuery?

I would like to be able to reorder lists of Models via a jQuery script. I already have reordering within inLines on the Model update page, but I'd like to add it to the change_list page aswell? Is this possible? I'm using Django 1.1 so have access to action sheets, if that makes things easier... Any information would be appreciated. ...

Django query for large number of relationships

I have Django models setup in the following manner: model A has a one-to-many relationship to model B each record in A has between 3,000 to 15,000 records in B What is the best way to construct a query that will retrieve the newest (greatest pk) record in B that corresponds to a record in A for each record in A? Is this something tha...