Wow, I'm having such a hard time on this. I must be doing something wrong, I'm getting an incredible ammount of queries.
So, my models are the following:
Player
Clan
Match (as in game match)
MatchMap (the maps played of a match)
MatchPlayer (the players of a match)
All of them are related via foreign key, no m2m relationship. A player ...
Hi,
I have a fairly complex relationship that I am trying to make work with the Django admin site. I have spent quite some time trying to get this right and it just seems like I am not getting the philosophy behind the Django models.
There is a list of Groups. Each Group has multiple departments. There are also Employees. Each Empl...
Let's say I have such model
class Event(models.Model)
users_count = models.IntegerField(default=0)
users = models.ManyToManyField(User)
How would you recommend to update users_count value if Event add/delete some users ?
...
I am adding date_added and date_modified fields to a bunch of common models in my current project. I am subclassing models.Model and adding the appropriate fields, but I want to add automated save behavior (i.e: evey time anyone calls MyModel.save(), the date_modified field gets updated. I see two approaches: overriding the save() method...
I have an app that lets people create tickets, and each Account owner using my app can create tickets.
Firstly, should it be unique per account do you think? Or, should it be completely unique?
Like this:
class Ticket(models.Model):
"""
An ticket created by an Account holder.
"""
account = models.OneToOneField('Account...
Hey all, I'm fairly new to both django and jquery, but have a couple years of general oo programming experience (mainly flash/flex/cf), and I'm trying to figure out the best way to implement a form for a sports tournament that manages a few model relationships and uses some simple jquery to improve usability.
My models look like this:
...
class Ticket(models.Model):
"""
An order placed by a customer.
"""
account = models.ForeignKey(Account)
client = models.ForeignKey(Client, choices=Client.objects.filter(account=self.account))
Obviously this wouldn't work because there is no instance available for 'self',but you can see what I'm trying to do here. I ...
Is this correct?
class Customer(models.Model):
account = models.ForeignKey(Account)
class Order(models.Model):
account = models.ForeignKey(Account)
customer = models.ForeignKey(Customer, limit_choices_to={'account': 'self.account'})
I'm trying to make sure that an Order form will only display customer choices that belong...
Lets say I have two django apps:
competitions - which will handle competition data
entries - which will handle functionality relating to entering competitors into competitions
In the competitions app I have a model which represents a section of a competition:
class Division(models.Model):
competition = models.ForeignKey(Competit...
Am building up a service that needs to maintain something along the lines of a case tracking system. Here's our model:
class Incident(models.Model):
title = models.CharField(max_length=128)
category = models.ForeignKey(Category)
status = models.ForeignKey(Status)
severity = models.ForeignKey(Severity)
owned_...
Hi guys, how can I execute such query in django:
SELECT * FROM keywords_keyword WHERE id not in (SELECT keyword_id FROM sites_pagekeyword)
In the latest SVN release we can use:
keywords = Keyword.objects.raw('SELECT * FROM keywords_keyword WHERE id not in (SELECT keyword_id FROM sites_pagekeyword)')
But RawQuerySet doesn't support ...
I have declared two of my models this way:
class EmailAddress(models.Model):
customer = models.ForeignKey(Customer)
email_address = models.CharField(max_length=200)
def __unicode__(self):
return self.email_address
class Customer(models.Model):
.
.
.
email_address = models.ForeignKey(EmailAddress)
def __unicode__(self):
...
Hi,
how do you use model formset in Django? When you do this:
from django.forms.models import modelformset_factory
OrderFormset = modelformset_factory(Order)
formset = OrderFormset()
formset has all Orders from DB...
How do I limit them for example to profile.orders (Profila is connected to Order with FK)?
Thanks in advance,
Etam.
...
does anybody know any gui builder of django models?
...
I have this:
class OrderForm(ModelForm):
class Meta:
model = Order
exclude = ('number',)
def __init__(self, *args, **kwargs):
super(OrderForm, self).__init__(*args, **kwargs)
if self.initial.get('account', None):
self.fields['customer'].queryset = Customer.objects.filter(account=self....
Hi,
I have a model with a decimal field. The output of:
def special_method(self):
return MyClass.objects.filter(product=self).order_by('-date_active')[0:1]
on this model is:
[<MyClass: 10.00>]
... and I have defined the following method on MyClass:
def __str__(self):
return str(self.rate)
This may be a silly question b...
Hi,
I defined a unicode() method in my Contact model.
def __unicode__(self):
return u'%s %s' % (self.first_name, self.last_name)
Now I want to show the return value of the unicode() method in a template.
But all that i try fails.
{{ object.unicode }}
or
{{ object.unicode() }}
or
{{ object.__unicode__ }}
or
{{ obj...
I have a model (and model form based on it) that has several time fields. I want these fields to be optional such that the user may leave some empty. My problem is that I continue to receive "Column 'mechreturn_tm' cannot be null" errors when I attempt to save an instance where one or more of these fields are blank. I've used the followi...
I'm trying to filter a table in django based on the value of a particular field of a foreign key.
For example I have two models - Project and Asset, Project has a "name" field and each asset has a ForiegnKey(Project) field. I'd like to filter my asset list based on the name of the associated project.
Currently I am performing two queri...
Hello,
say I have such model:
class Foo(models.Model):
name = models.CharField("name",max_length=25)
type = models.IntegerField("type number")
after doing some query like Foo.objects.filter(), I want to group the query result as such:
[ [{"name":"jb","type:"whiskey"},{"name":"jack daniels","type:"whiskey"}],
[{"name":"absolute","...