I have 2 models with a 1-1 relation (essentially a resource pool). For the example code, I will simply use nuts and bolts. There will be many more nuts (available resources) than bolts (which will each require 1 nut). However, if a nut can only be assigned to one bolt.
The constraint is easy enough to set up with the unique=True name...
Ok, so I posted a question recently regarding an error when adding a ManyToManyField
The Models are the ones below
class MagicType(models.Model):
name = models.CharField(max_length=155)
parent = models.ForeignKey('self', null=True, blank=True)
class Spell(models.Model):
name = models.CharField(max_length=250, db_index=...
I have a problem when I update an object. This is the model:
class HourRecord(models.Model):
day_of_work = models.PositiveIntegerField(max_length=1)
date_of_work = models.DateField(verbose_name='creation date')
who_worked = models.ForeignKey(User)
project = models.ForeignKey(Project, related_name='hour_record_set', null=...
Hi,
I'm using the contenttypes framework to create a "featured content" feature on my site. I've basically done this by defining a model like so:
class FeaturedContent(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_ty...
Am I thinking about this all wrong, or am I missing something really obvious?
Python's style guide say's less code is better (and I don't think that's subjective... It's a fact), so consider this.
To use forms for all validation means that to write a model field subclass with custom validation, you'd have to:
Subclass models.Field
Su...
Hi,
Sent a question yesterday but I wasn't too clear on what I am attempting. I'm struggling to find any useful tutorials on how best to achieve this so a nudge in the right direction would be greatly appreciated.
I've set up a model which references django_content_type. My idea is to use this model to reference other models so that th...
I ahve a multi tenant Django database. All my multi tenant enabled models import from a class AccountSpecificModel, which as a FK to a class Account. Now I have some unique=True and unqiue_together in Meta, which do not specify account.
In my scenario, for AccountSpecificModel uniqueness has no menaing unless it takes care of account, w...
Let's say I have a CarModel(models.Model) that uses price = models.DecimalField():
import CarModel
car = CarModel(name='Corvette', price='Hello World')
Traceback (most recent call last):
...
ValidationError: 'price needs to be a Decimal()'
The error was basically that.
Since the price was expecting a decimal but received a string, i...
Hi
I have created an article site, where articles are published in several languages. I am using transmeta (http://code.google.com/p/django-transmeta/) to support multiple languages in one model.
Also I am using generic comments framework, to make articles commentable. I wonder what will happen if the same article will be commented in ...
I'm looking to add a method that my Ticket model has called process to the admin, so that I could click a link in the list view, and "process" my model instance (do an API call behind the scenes).
To clarify:
class Ticket(models.Model):
title = models.CharField(max_length=255)
def process(self):
... hardcore processing...
Greetings
I am hacking Django and trying to test something such as:
Like woot.com , I want to sell "an item per day", so only one item will be available for that day (say the default www.mysite.com will be redirected to that item),
Assume my urls for calling these items will be such: www.mysite.com/item/<number>
my model for item:
c...
Say I have a ticket and this ticket has an owner and a taker. The owner ID is set when the ticket is created and the taker ID is set to default to NULL. In this case the taker may NOT also be the owner. I know this is trivial to do in the progamming logic but I am wondering if it can be done in the database.
Setting the two fields to u...
Hi,
I'd like to create a reusable Django app that handles status updates of the Users. Much like facebook's "news feed".
Use cases includes, for example:
A Professor can create an Assignment due to an specific date and every student can see on the news feed that the assignment was created, with a short description, the date that it's...
I am attempting to create a profile page that shows the amount of dwarves that are assigned to each corresponding career. I have 4 careers, 2 jobs within each of those careers and of course many dwarves that each have a single job. How can I get a count of the number of dwarves in each of those careers? My solution was to hardcore the...
Thanks to some fantastic help on a previous question I have managed to put together my query. Everything works swimmingly save one issue.
careers = Career.objects.filter(job__dwarf__user = 1).annotate(dwarves_in_career = Count('job__dwarf'))
In my view this does exactly what I want and when I loop it in my template like so:
{% f...
Hello guys,
I've looked at formset and model formset at Django many times, but I still can't figure the smart way to do this.
I have two models:
Group
Person
I have a queryset that contains all the persons trying to join a particular group: Person.objects.filter(wantsToJoinGroup=groupD)
Now, what I want to do, is display a page wit...
To sum things up before I get into bad examples, et al: I'm trying to make an application where I don't have to write code in all my models to limit choices to the current logged in account (I'm not using Auth, or builtin features for the account or login).
ie, I don't want to have to do something like this:
class Ticket(models.Model):...
class SupercalifragilisticexpialidociousManager(models.Manager):
# Sorry, I'm sick of Foo and Spam for now.
def get_query_set(self, account=None):
return super(SupercalifragilisticexpialidociousManager,
self).get_query_set().filter(uncle=model_thats_using_this_manager_instance.uncle)
The magic I'm l...
class Account(models.Model):
identifier = models.CharField(max_length=5)
objects = MyCustomManager()
class Meta:
abstract = True
class Customer(Account):
name = models.CharField(max_length=255)
If I have a lot of models, and I want to save time from having to put foreignkeys everywhere, is ...
I'm trying to figure out how I can use the type() module to dynamically create a Django model based on existing DB tables without having to either write it out manually or use the manage.py generator to inspect the DB. Reason is my schema changes frequently -- adding new tables, adding/deleting columns, etc. Anyone have a good solution...