django-models

Django - Model with 2 foreign keys from the same class

I wanted a Django model with 2 foreign keys from the same table. It's an event table which has 2 columns for employees: the 'home' and the 'away'. But I get this error: Error: One or more models did not validate... class Team(models.Model): name = models.CharField(max_length=200) class Match(models.Model): home = models.Foreign...

Django: how to rearrange object ids

I've started a model with the default, automatically handled IDs Django provides. Now I've started interfacing with an external system which has its own IDs for the same objects, and it would be very convenient to align my own IDs with the external system's. However, the numerical ranges overlap, so a naive solution wouldn't work. Is ...

Relational Fields - Django

Hi, I am making a product app to add machines to a product list. Every product had a list of features, like motor type, motor output. Not all have the same features. Each feature has a value, like 2W, 1.5m etc, but this will only be put in once you add a product. So I wanna add all the possible features to my feature model. Then when I ...

Django restart server or httpd

In django framework,When there are changes in urls.py or model.py or views.py .We would restart httpd. But as the documentation says we could restart runserver to get the latest changes. Which is the best efficient way for doing the above ...

Creating a Relation in __init__ of a model (in Django)

Lets assume I had the following Model class A(Models.model): def __init__(self,data): B(a=self,data=data).save() class B(Models.model): data = somefieldtype a = Models.models.ForeignKey('A') now as you might suspect, there is an error in this Model definintion, as one cannot create a relation to the A instance before a...

Filtering Model formsets

First try at playing with model formsets with django and was wondering how to filter by the logged in user. The view below renders a form with all the profiles when I only want them to list one (the user's one). def create_profile(request): ProfileFormSet = modelformset_factory(Profile) if request.method == 'POST': formset...

Django GenericManyToMany ?

Hi all! I want to make my Book model belongs to multiple Libraries, Collections, References and Editors, together. Is it possible to do it with generic relations ? Like that : content_type = generic.GenericManyToMany(ContentType) Thanks. from django.conf import settings from django.contrib.contenttypes import generic from django.con...

How to work with settings in Django

I want to keep some global settings for my project in Django. I need to have access to these settings from the code. For example, I need to set a current theme for my site that I can set using admin console or from the code. Or I need to set a tagline that will show in the header of all pages. I suppose I should use models for keeping th...

South does not recognize models when it is a package

I use South for schema and data migraton for my Django site. I'm happy about using it. One day I converted models.py file to models/__init__py and put some additional models at models/something.py. When I ran python manage.py schemamigration app --auto, I got the Nothing seems to have changed. message despite of the new classes at someth...

Django ORM with Postgres: rows unexpectedly deleted - Bug?

Hi, I have the problem that objects were unexpectedly deleted and created a minimal example. I dont't know whether it's a bug or if a made a thinking error. The models are something like that: class A(models.Model): related = models.ForeignKey('C', blank = True, null = True) class B(models.Model): title = models.CharField(max...

Two foreign keys and a value in django template

I am a newbie to django, so the question might be dumb, but please feel free to teach me the right way if you know it. I tried googling the issue, but I am still at loss. Here's my problem: I have a class in my model that has two foreign keys: class X(models.Model): name = models.CharField(max_length=30) def __unicode__(self): ...

Saving a StackedInline foreign keyed model before primary model in Django Admin

I have four models with the relationships Model PagetTemplate(models.Model): pass Model TextKey(models.Model): page_template = models.ForeignKey(PageTemplate, related_name='text_keys') Model Page(models.Model): page_template = models.ForeignKey(Pagetemplate, related_name='pages') Model Text(models.Model): key = model...

Django Google app engine reference issues.

Hi all, I am working on an application on Django and google application engine. In my application I have several models with several ReferenceProperty fields. The issue is that if any of the ReferenceProperty field gets deleted it produces a ReferenceProperty related errors in all the other models where it has been used. What I want is...

Generating a non-sequential ID/PK for a Django Model

I'm on the cusp of starting work on a new webapp. Part of this will give users pages that they can customise in a one to many relationship. These pages naturally need to have unique URLs. Left to its own devices, Django would normally assign a standard AUTOINCREMENT ID to a model. While this works fantastically, it doesn't look great an...

Django string in unicode pattern

Django when i send the following string from an ajax submit i get the following string in unicode.How to decode this $.post("/records/save_t/",snddata, function(data){ if(data == 0 ){ } },"json"); In django def save_t(request): if request.method == 'GET': qd = request.GET elif request.method =...

problem with Django model

Hi :) , I use Djnago a few weeks ago I started a django app and wrote these lines in model.py from django.db import models class Publisher(models.Model): name = models.CharField(max_length=30) address = models.CharField(max_lenght=50) city = models.CharField(max_length=60) state_province = models.CharField(max_lengt...

Django ModelForm

Hi all, I am trying to create a simple CRUD with ModelForm. It works fine except that every time I edit, saving creates a new instance of the data. So i edit and get an extra row in DB instead of an updated one. I am at a loss as to how it knows to save an existing charity as it does not store the PK (id) as a hidden field in the form. ...

How to aggregate records in django based on multiple criteria

Lets say, I have following models in my Django app. class EventGroup name = models.CharField() class Event(models.Model): name = models.CharField() group = models.ForeignKey(EventGroup) class Severity(models.Model): name = models.CharField() group = models.ForeignKey(EventGroup) class LogEntry(models.Model): t...

Django current site site domain sitemap

How do I get my sites landing page to appear in the sitemap.xml ? I know you can add the other ones by means of djangos sitemap contrib. ...

Write-once fields in Django models

Hi, I'm having a pretty hard time trying to create a write-once field in a Django model. Ideally I'd want it to work like a final variable, although I can settle for simply preventing it from being edited through the admin. I know there is a solution for read-only fields, but it also affects the add form, and I don't want the field to...