django-models

Get a queryset of objects through an intermediary model

I want get all of the Geom objects that are related to a certain content_object (see the function I'm trying to build at the bottom, get_geoms_for_obj() class Geom(models.Model): ... class GeomRelation(models.Model): ''' For tagging many objects to a Geom object and vice-versa''' geom = models.ForeignKey(Geom) content_...

Django Categories with Subcategories, and urls

Hi guys, im trying to make Categories and Subcategories, im checking this models but i have this error: Truncated incorrect DOUBLE value: 'nacionales' where the "nacionales" is the parent Category, i know that my problem maybe are in the urls.py, but the true, i dont know how set the urls for this case... my model.py: # from ... cla...

How to Model a Foreign Key in a Reusable Django App?

In my django site I have two apps, blog and links. blog has a model blogpost, and links has a model link. There should be a one to many relationship between these two things. There are many links per blogpost, but each link has one and only one blog post. The simple answer is to put a ForeignKey to blogpost in the link model. That's al...

.filter across tables in Abstract model class - Django

My model is like this class Foo(models.Model): user = models.ForeignKey(User) class Meta: abstract = True class Bar(Foo): bar_thing = models.CharField(..) class Baz(Foo): baz_thing = models.CharField(..) I want to get all bar, baz (And other FooSubclasses) which have user__username = 'hello' i do Foo.object...

Django: reverse list of many to many relationship?

Hi, I have two simple models in models.py: Service and Host. Host.services has a m2m relationship with Service. In other words, a host has several services and one service can reside on multiple hosts; a basic m2m. models.py class Service(models.Model): servicename = models.CharField(max_length=50) def __unicode__(self):...

Django data creation and commits

I'm not sure I 100% understand what the database does. If I just have some misconception, please point it out. Let's say I have a function that wants to create 100 new entry in the database with has 100,000 entries. It seems a lot faster when those 100 entries get create and the commit is made after the last entry is created. Now, if ...

Storing an Integer Array in a Django Database

What is the best way to store an array of integers in a django database? ...

Django, category and subcategories

Hi guys, im working category and subcategories with the DataModel, all is fine in this part, but i need to use my category and subcategories in my Menu Nav, im try to use this Jquery menu , and im rendering my menu with subcategories, but im lost with rendering the subcategories in the way: <ul> <li> <a href="#">Category</a> ...

Help with Admin forms validation error

Hi Guys, I am quite new to Django, I'm having few problems with validation forms in Admin module, more specifically with raising exceptions in the ModelForm. I can validate and manipulate data in clean methods but cannot seem to raise any errors. Whenever I include any raise statement I get this error "'NoneType' object has no attribute...

Django Relationships

Hi I'm new at Django and have a few problems getting my mind around manytomany relatiosnhips and Manytoone (i.e Foreign key). My setup is this. I have class A, Class B, Class C Every Class B object must belong to a Class A object. They cannot belong to more than one Class A object. A more practical example could be if Class A is a Mus...

Retrieving values from 2 different tables with Django's QuerySet

For the following models: class Topping(models.Model): name = models.CharField(max_length=100) class Pizza(models.Model): name = models.CharField(max_length=100) toppings = models.ManyToManyField(Toppping) My data looks like the following: Pizza and Topping tables joined: ID NAME TOPPINGS --------------------...

manage.py syncdb doesn't add tables for some models

My second not-so-adept question of the day: I have a django project with four installed apps. When I run manage.py syndb, it only creates tables for two of them. To my knowledge, there are no problems in any of my models files, and all the apps are specified in INSTALLED_APPS in my settings file. Manage.py syndb just seems to ignore two ...

Does model.CharField('blank=False') work with save()?

I've a model like this with django 1.1: class Booking(models.Model): name = models.CharField(max_length=100) By default, I'm reading that both 'null' and 'blank' are False. So with a test like this... class SimpleTest(TestCase): def test_booking_save(self): b = Booking() b.save() ... I expected the save to ...

Django tracking app?

Is there an application for django which tracks CRUD for objects inside a project? ...

django init function with attrs in Form

Hi guys, im using Django Profiles, and i need to make some change in the profile form. In the normal way my form is fine completly, but now i would like a litter change, add jquery for repopulate a select form. The problem is that Django Profile make the form from the model, so i would like to add a attribute id to the select form (i d...

Django Models internal methods

I'm new to Django so I just made up an project to get to know it but I'm having a little problem with this code, I want to be able to as the car obj if it is available so I do a: >>>cars = Car.objects.all() >>>print cars[0].category >>>'A' >>>cars[0].available(fr, to) that results in a: >>>global name 'category' is not defined So i...

Django admin choice field dynamically populated by generic foreign key's model fields

Say I have the following simple models for some tagging application (this is simplified from the actual code): # Model of tag templates class TagTemplate(models.Model): name = models.CharField() content_type = models.ForeignKey(ContentType) class Tag(models.Model): template = models.ForeignKey(TagTemplate) object_id = m...

Problems with django managers

Hi! I have following model: class UserProfile(models.Model): """ User profile model, cintains a Foreign Key, which links it to the user profile. """ about = models.TextField(blank=True) user = models.ForeignKey(User, unique=True) ranking = models.IntegerField(default = 1) avatar = models.ImageField(uploa...

Django ORM, filtering objects by type with model inheritence.

So I have two models... Parent and Child. Child extends Parent. When I do Parent.objects.all(), I get both the Parents and the Children. I only want Parents Is there a Parent.objects.filter() argument I can use to only get the Parent objects instead of the objects that extend parent? ...

Alternate datasource for django model?

I'm trying to seamlessly integrate some legacy data into a django application. I would like to know if it's possible to use an alternate datasource for a django model. For example, can I contact a server to populate a list of a model? The server would not be SQL based at all. Instead it uses some proprietary tcp based protocol. Copying ...