django-models

How should multiple Django apps communicate with each other?

Other posters have previously said in this forum that when your Django app starts getting big and unmanageable, you should split it up into several apps. I'm at that point now. What are the best practices for allowing communication between these apps? One of my apps (let's call it Processor) processes very large data sets. Once an hour ...

How to associate multiple types of tags per model in django

I am little new to django and trying to find best ways to do things instead of writing everything myself. I am working on a model where I need multiple types of tags to be associated with a model and then I want to retrieve the objects using multiple filtering criteria. I see that in django-tagging tags are stored per model so I think it...

manage.py syncdb error, postgres_psycopg2

Hello, I'm trying to install a shopping cart plugin for django but having a problem when I run manage.py syncdb. When run, it installs 4 tables, then I'm getting the following error message: File "(mypath)/django/db/backends/postgresql_psycopg2/base.py", line 44, in execute return self.cursor.execute(query, args) django....

How do I get syncdb db_table and app_label to play nicely together

I've got a model that looks something like this: class HeiselFoo(models.Model): title = models.CharField(max_length=250) class Meta: """ Meta """ app_label = "Foos" db_table = u"medley_heiselfoo_heiselfoo" And whenever I run my test suite, I get an error because Django isn't creating the tables for tha...

Best way to create Singleton Table in Django/MySQL

I want a table which can only have one record. My current solution is: class HitchingPost(models.Model): SINGLETON_CHOICES = (('S', 'Singleton'),) singleton = models.CharField(max_length=1, choices=SINGLETON_CHOICES, unique=True, null=False, default='S'); value = models.IntegerField() def __unicode__(self): ret...

django form doesn't work on click submit

Hi! I'm trying to do a form, with gender choices. The user could choice between male or female. What I have now in forms.py: class GenderForm(forms.Form): demo = DemoData.objects.all() GENDER_CHOICES = [ ('Male', 'Masculino'), ('Female', 'Feminino')] gender = forms.ModelChoiceField(demo, widget=Select(), r...

Python: interact with complex data warehouse

We've worked hard to work up a full dimensional database model of our problem, and now it's time to start coding. Our previous projects have used hand-crafted queries constructed by string manipulation. Is there any best/standard practice for interfacing between python and a complex database layout? I've briefly evaluated SQLAlchemy, S...

How should I model this out?

I am a bit stuck on how I should model this out. Here is what I have: I have a model called Location. In this model I have postal code, city, region, longitude, and latitude. This data is pre-populated with all of Canada's stuff. You can imagine this table is quite large. This is what I would like to achieve by stuck on how to model ...

Set default value to UserProfile model field from User instance field

I use UserProfile model for keeping additional info about user and one of the fields is subdomain variable that is by default should be set to username. Here is UserProfile model: class UserProfile(models.Model): theme = models.ForeignKey(Theme, unique=True, null=True) user = models.ForeignKey(User, unique=True) subdomain = ...

Django Models (1054, "Unknown column in 'field list'")

No idea why this error is popping up. Here are the models I created - from django.db import models from django.contrib.auth.models import User class Shows(models.Model): showid= models.CharField(max_length=10, unique=True, db_index=True) name = models.CharField(max_length=256, db_index=True) aka = models.CharField(max_le...

How To Create A Form With Generic Relations In Django

Hi, How can I create a Form with normal form elements and generic elements together as ModelForm For using frontend CRUD. For example; Generic Model: class Todo(models.Model): user = models.ForeignKey(User, related_name="todo") title = models.CharField(max_length=100, unique=False) slug = models.SlugField(max_length=50) ...

Post create instance code call in django models

Hi folks, Sorry for some crazy subj. I'd like to override django models save method and call some additional code if the model instance is newly created. Sure I can use signals or check if the model have empty pk field and if yes, create temporary variable and later call a code: Class EmailModel(models.Model): email = models.Emai...

Django generic foreign key and select_related

Hello guys, I'm trying to do select a model using a relation with a generic foreign key, but it's not working as expected. I think it's better illustrated and understandable with code class ModelA(models.Model): created = models.DateTimeField(auto_now_add=True) class ModelB(models.Model): instanceA = models.ForeignKey(ModelA) cont...

Appengine - Reportlab (Get Photo from Model)

I´m using Reportlab to generate a PDF. Can´t retrieve a photo from a model. #Personal Info p.drawImage('myPhoto.jpg', 40, 730) p.drawString(50, 670, 'Your name:' + '%s' % user.name) p.drawImage (50, 640, 'Photo: %s' % (user.photo)) When i create on generate PDF, i got this error: Traceback (most recent call last)...

Django query - "case when" with aggregation function

I have the following django model (mapped to table 'A'): class A(models.Model): name = models.CharField(max_length=64, null=False) value = models.IntegerField() ... I want to perform the following simple query on top: select avg(case when (value > 0 and value <= 50) then 0 when (value > 50 and value < 70...

Django: Model Inheritance: What apps should be installed?

I am in the process of setting up a rather complex data structure, where models inheriting from models are subsets of the original models file. > level_1_a > level_2_a > level_3_a > level_4_a > level_4_b > level_3_b > level_4_a > level_2_b > level_3_a > level_4_a > level_4_b ...

IntegrityError while saving a new item to the postgresql db in django?

Django saves the data but eventually raises an IntegrityError. If there is an error, why it is saving that data? And I'm sure that the uniqueness property is not violated on that data. What is going on? Why is that error occurs? and how can I solve that? ...

Calling function when model is called by django-admin

Hello! I have something like this in my model: class Artykul(models.Model): id = models.AutoField(max_length = 5, primary_key = True) tytul = models.CharField(max_length = 255) kategoria = models.ManyToManyField(Title, limit_choices_to = choices_limit) dodano = models.DateField(auto_now_add = True) autor = models.CharField(max_leng...

Django notification on comment submission

I am making use of Django's contrib.comments and want to know the following. Are there any utils or app out there that can be plugged into an app that sends you a notification when a comment is posted on an item? I haven't really worked with signals that much, so please be a little bit descriptive. This is what I came up with. from d...

How do I create a Django model field that evaluates based on other fields?

I'll try to describe my problem with a simple example. Say I have items of type Item and every item relates to a certain type of Category. Now I can take any two items and combine into an itemcombo of type ItemCombo. This itemcombo relates to a certain category called ComboCategory. The ComboCategory is based on which categories the item...