I'm trying to make some types in Django that map to standard Django types. The custom model field documentation goes into complicated cases; I just want to store a basic Django type from a class with a bunch of handy methods.
For example, if I were storing playing cards, I want something like:
class Card(object):
""" A playing car...
Today I'm starting a little project to create a Django based school administration program. I'm currently designing the models and their corresponding relationships. Being rather new to Django and relational databases in general, I would like some input.
Before I show you the current model layout, you need to have an idea of what the pr...
I'm trying to find the actual class of a django-model object, when using model-inheritance.
Some code to describe the problem:
class Base(models.model):
def basemethod(self):
...
class Child_1(Base):
pass
class Child_2(Base):
pass
If I create various objects of the two Child classes and the create a queryset con...
I have a MultipleChoiceField on a form holding car makes. I want to filter my database of cars to the makes that were checked but this causes a problem. How do I get all the Q(make=...) statements in dynamically?
How I start: ['value1', 'value2', ...]
How I want to end: Q(col='value1') | Q(col='value2') | ...
I've couple of other meth...
I just got done working through the Djano tutorials for the second time, and am understanding things much more clearly now. However, I'm still unclear how apps inside a site interact with one another.
For example, lets say I'm writing a blog application (a rather popular activity, apparently). Blog posts and comments tend to go together...
I'm working on a blog application in Django. Naturally, I have models set up such that there are Posts and Comments, and a particular Post may have many Comments; thus, Post is a ForeignKey in the Comments model.
Given a Post object, is there an easy way (ideally, through a method call) to find out how many Comments belong to the Post?
...
I have several Models and want to return a queryset of all the Models belonging to a User, I'm wondering if its possible to return one Queryset from multiple Models?
...
Pretty new to this scene and trying to find some documentation to adopt best practices. We're building a fairly large content site which will consist of various media catalogs and I'm trying to find some comparable data / architectural models so that we can get a better idea of the approach we should use using a framework we've never ma...
I've factored out common attributes from two classes into an abstract base class, however I have another model that needs to reference either one of those classes. It's not possible to reference an ABC as it doesn't actually have a database table.
The following example should illustrate my problem:
class Answer(models.Model):
ovram...
I'd like to write a script that interacts with my DB using a Django app's model. However, I would like to be able to run this script from the command line or via cron. What all do I need to import to allow this?
...
What is the preferred naming convention for Django model classes?
...
I have a Client and Groupe Model.
A Client can be part of multiple groups.
Clients that are part of a group can use its group's free rental rate at anytime but only once. That is where the intermediary model (ClientGroupe) comes in with that extra data.
For now, when I try to save the m2m data, it just dies and says I should use the C...
I have the following classes: Ingredients, Recipe and RecipeContent...
class Ingredient(models.Model):
name = models.CharField(max_length=30, primary_key=True)
qty_on_stock = models.IntegerField()
def __unicode__(self):
return self.name
class Recipe(models.Model):
name = models.CharField(max_length=30, primary_...
Is there a way of doing the following?
model = "User"
model.objects.all()
...as opposed to User.objects.all().
EDIT: I am trying to make this call based on command-line input. Is it possible to avoid the import statement, e.g.,
model = django.authx.models.User
? Django returns an error, "global name django is not defined."
...
I am working on a Django application which contains an Offer model. An Offer instance contains the pricing conditions and points to a product definition. The product model is actually a hierarchy (I have a Television model, a Camcorder model, etc.). So I would like the Offer model to contain a polymorphic (or "generic") association to...
I'd like to have the full history of a large text field edited by users, stored using Django.
I've seen the projects:
Django Full History (Google Code)
Django ModelHistory, and
Django FullHistory
I've a special use-case that probably falls outside the scope of what these projects provide. Further, I'm wary of how well documented, te...
When I read django code I often see in models what is called a "slug". I am not quite sure what this is but I do know it has something to do with URL:s. How and when is this slug-thing supposed to be used?
(I have read it's definition in this glossary)
...
I have models (simplified example):
class Group(models.Model):
name = models.CharField(max_length = 32)
class Person(models.Model):
group = models.ForeignKey(Group)
class Task(models.Model):
group = models.ForeignKey(Group)
people = models.ManyToManyField(Person)
def save(self, **kwargs):
ppl = Person.objects.all().filt...
Hi, i have very simple problem. I need to create model, that represent element of ordered list. This model can be implemented like this:
class Item(models.Model):
data = models.TextField()
order = models.IntegerField()
or like this:
class Item(models.Model):
data = models.TextField()
next = models.ForeignKey('self')
...
By default when Django runs against sqlite backend it creates a new in memory database for a test. That means for every class that derives from unittest.TestCase, I get a new database. Can this be changed so that it is cleared before every test method is run?
Example: I am testing a manager class that provides additional abstraction on ...