You have models:
class Order(Model):
date = DateField(editable = False, auto_now_add=True)
status = CharField(max_length = 1, choices = STATUS, default = 'N')
profile = ForeignKey(Profile, related_name = 'orders', blank = True, null = True)
shipping = ForeignKey(Shipping, related_name = 'orders', blank = True, null = True)
address ...
I have these models in Django:
class Customer(models.Model):
def __unicode__(self):
return self.name
name = models.CharField(max_length=200)
class Sale(models.Model):
def __unicode__(self):
return "Sale %s (%i)" % (self.type, self.id)
customer = models.ForeignKey(Customer)
total = models.DecimalField...
I've already defined a model and created its associated database via manager.py syncdb. Now that I've added some fields to the model, I tried syncdb again, but no output appears. Upon trying to access these new fields from my templates, I get a "No Such Column" exception, leading me to believe that syncdb didn't actually update the datab...
I have a problem with deleting my objects. I wrote a delete method which get a list of IDs of objects to be deleted. This works fine for objects and for objects with foreign keys, but it fails if i have a OneToOneField relationship to the object which i want to delete.
This is my delete method:
@login_required
def delete_objects(reques...
I'm not sure if I just can't concentrate or what, but I feel like this should be easy to do. I have 2 models, one that references the other as a simple foreign key relation (one-to-many) now in the template I want to display this relation as a nested unordered lists.
...
Hello everyone,
I have checked several other threads but I am still having a problem. I have a model that includes a FileField and I am generating semi-random instances for various purposes. However, I am having a problem uploading the files.
When I create a new file, it appears to work (the new instance is saved to the database), a f...
Is there a simple way I can add a "WikiField" to a model I have in my application?
I think the most important requirements are:
A text field that can be added to any model.
simple wiki markup or editor widget that enables text formatting and easy insertion of links and images.
saves revision history with author information, and easily...
I have an AppEngine app that I'm migrating to run in Django, using app-engine-patch to get all the goodness of Django - particularly the Admin interface.
One of my models looks like (partially) this:
class Request(db.Model):
requestor = db.UserProperty(auto_current_user_add=True)
When I display a form based on this model I don't di...
I have multiple models which all have a FK to the same model.
All I know is the FK how can I determine which of the models has the FK attached?
Below an example to clearify:
class ModelA(models.Model):
title = models.CharField("title", max_length=80)
class ModelB(models.Model):
fk = models.ForeignKey(ModelA)
class ModelC(...
Hi,
I have an Address Model which has a ForeignKey to a Contact Model:
class Address(models.Model):
street = models.CharField(max_length=25)
postal_code = models.CharField(max_length=25)
city = models.CharField(max_length=50)
country = models.CharField(max_length=50)
contact = models.ForeignKey(Contact, related_name...
I have the following model:
class A(models.Model):
name = models.CharField(max_length=50)
content_type = models.ForeignKey(ContentType)
This model is supposed to be the root model in some inheritance tree and content_type attribute is a kind of a hint about what type is really stored.
Obviously, I should calculate content_type...
There's probably an obvious way to do this that I'm missing, so sorry for the noobish question.
I've got models like this:
class Speaker(models.Model):
name = models.CharField(max_length=50)
class Talk(models.Model):
title = models.CharField(max_length=50)
speaker = models.ForeignKey(Speaker)
How can I elegantly get a li...
I want to overwrite the custom objects model manager to only return objects a specific user created. Admin users should still return all objects using the objects model manager.
Now I have found an approach that could work. They propose to create your own middleware looking like this:
#### myproject/middleware/threadlocals.py
try:
...
I want to build an undirected graph in Django. I have built an edge model with two foreign keys (first,second) to the node class, but there is a conflict with the related_name. I can use first_set and second_set, but since the graph is undirected, it doesn't matter if it is being liked to or from. What is the recommended way to deal w...
I have two models than inherited from the same abstract base class.
I would expect to be able to get all instances from classes that are children of the base class with something like AbstractClass.objects.all()
Of course I could join queries on all children but that's awful and it stops working if I add new children class.
Is this p...
Hello
How can I do something like this :
products_list = Product.objects.all()
for key in keywords:
products_list = products_list.filter(name__icontains=q)
This don't work.
Thank you for your help
...
I'm running into a paradigm problem here. I don't know whether I should store money as a Decimal(), or if I should store it as a string and convert it to a decimal myself. My reasoning is this:
PayPal requires 2 decimal places, so if I have a product that is 49 dollars even, PayPal wants to see 49.00 come across the wire. Django's Decim...
I'm trying to query an object and when I hard code the value it works but when I use a variable for it the query doesn't work.
Here's the class:
class AdvertisementType(models.Model):
type = models.CharField(max_length='40')
description = models.CharField(max_length='80')
def __unicode__(self):
return '%s' % self.t...
Does this facade code look like a good idea, or is there anything inherently flawed about the design? More importantly, is there a problem I will likely run into down the road with this code? Any help is much appreciated.
I'm trying to build this so that I can have a Payment class as my facade, which accepts cc numbers, etc. and a PayPa...
Some of my unit tests take 10-15 seconds just for mysql to create the tables. This seems unnecessarily long. It has to create around 50 tables, but that's still only 3 tables per second. This is a big annoyance when running unit tests over-and-over.
As a workaround, I have been running my unit tests in sqlite3. It is blazing fast, but ...