0
голосов
3ответов
210 просмотров

How do you model this in django?

Considering the class model as follows: alt text http://www.forteresse.net/site/stackoverflow/classes.png/image How do you do this in models.py? class House(models.Model): foo = models.CharField(max_length=123) class Caravan(models.Model): foo = models.CharField(max_length=123) class...

1
голосов
1ответов
866 просмотров

Complex query in Django

Maybe a simple question, but i've just started to work with Django after a few years of php experience :-) Problem: we have a pair of models - "Categories" and "Post". "Categories" is nested sets tree of post categories, "Post" is plain list of blog posts with ForeignKey field, linked to Categor...

1
голосов
2ответов
149 просмотров

django and executing a separate .py to manipute a database

I want to execute a random .py file, say foo.py on the myproject/myapp folder by using crobjob by some periods I have this basic model in my model.py for the app: class Mymodel(models.Model): content = models.TextField() Say I have this in my foo.py, I want to check if there is any Mymode...

0
голосов
2ответов
742 просмотров

Storing wiki revisions on Google App Engine/Django - Modifying This Existing Code

In the past, I created a Django wiki, and it was fairly straightforward to make a Page table for the current wiki entries, and then to store old revisions into a Revision table. More recently, I decided to set up a website on Google App Engine, and I used some wiki code that another programmer w...

5
голосов
3ответов
3899 просмотров

Django inheritance: how to have one method for all subclasses?

I have a model BaseModel and several subclasses of it ChildModelA(BaseModel), ChildModelB(BaseModel), ... using multi-table inheritance. In future I plan to have dozens of subclass models. All subclasses have some implementation of method do_something() How can I call do_somthing f...

64
голосов
5ответов
49294 просмотров

How to update multiple fields of a django model instance?

I'm wondering, what is a standard way of updating multiple fields of an instance of a model in django? ... If I have a model with some fields, Class foomodel(models.Model): field1 = models.CharField(max_length=10) field2 = models.CharField(max_length=10) field3 = models.CharField(max...

1
голосов
2ответов
441 просмотров

Can I use Django's Generic Views with google-app-engine-django?

Put simply, is there a way to get generic views to work? If I try the following in urls.py: publisher_info = { 'queryset': Publisher.objects.all(), } urlpatterns = patterns('', (r'^publishers/$', list_detail.object_list, publisher_info) ) I get the following error: AttributeError a...

111
голосов
2ответов
53468 просмотров

Can a dictionary be passed to django models on create?

Is it possible to do something similar to this with a list, dictionary or something else? data_dict = { 'title' : 'awesome title', 'body' : 'great body of text', } Model.objects.create(data_dict) Even better if I can extend it: Model.objects.create(data_dict, extra='hello', extra2='w...

5
голосов
1ответов
4350 просмотров

Create & return a default ImageFieldFile from inside a function

In my UserProfile model I would like to have a function which returns either the user's ImageFileField object or a default image if the user has not uploaded their own. For example: class UserProfile(models.Model): pic = models.ImageField('Headshot',blank=True, ...

3
голосов
1ответов
3149 просмотров

Custom form in inline form

I have a custom form to display goals. Goals are edited inline in a Game. class GoalForm(forms.ModelForm): class Meta: model = Goal def __init__(self, *args, **kwargs): super(GoalForm, self).__init__(*args, **kwargs) self.fields['goal_scorer'].queryset = Player.objec...

5
голосов
3ответов
1651 просмотров

How to organize Django project with abstract models

I have a few models: 'Article, Video, BlogPost, News, Commodity'. Each are in their own application. They all are basically the same models with a few extra fields on each. But each share about 15 fields. I'm using an abstract base class. I'm trying to figure out how I should do organization for...

1
голосов
1ответов
338 просмотров

In Django, How Do I Move Images When A Dynamic Path Changes?

I have a Django app with an image field (a custom ThumbnailImageField type) that auto-generates the file path for an image based on the title, type, and country of the item the image is attached to (upload_ to = get_ image_path). Here's how: def get_image_path(instance, filename): dir = 'i...

30
голосов
5ответов
6077 просмотров

How to save a model without sending a signal?

How can I save a model, such that signals arent sent. (post_save and pre_save)

1
голосов
2ответов
1818 просмотров

Saving ForeignKey objects in Django

I'm completely stumped as to why this isn't working: flight = Flight.objects.get(pk=flight_id) print "old", flight.route.pk ## `route` is a ForeignKey field to model Route print "new", new_route.pk flight.route=new_route # new_route is a newly created Route object flight.save() print "db", Flig...

0
голосов
2ответов
655 просмотров

Use Choices from Models in a template tag

I have a model with a bunch of choices, that are in the DB configured as below. COL_CHOICES =( (1, 'Not Applicable'), (2, 'Black'), ) COL2_CHOICES =( (1, 'Green'), (2, 'Blue'), ) etc. I want to display all these options as a men...

31
голосов
2ответов
23153 просмотров

How to set django model field by name?

This seems like it should be dead simple, so I must be missing something. I just want to set the value of a field in my model instance by name. Say I have: class Foo(Model): bar = CharField() f = Foo() I want to set the value of bar by name, not by accessing the field. So something like: f...

2
голосов
1ответов
1015 просмотров

In Django QuerySet, how do I check for a specific object in a ManyToMany field?

I have the following models: class Topping(models.Model): ... class Pizza(models.Model): toppings = models.ManyToManyField(Topping) I then have a topping object: cheese = Topping.objects.get(name='cheese') I then find all pizzas with the cheese topping with the following query: Pi...

1
голосов
4ответов
2878 просмотров

The Installer could not find Models of cms app in Django-CMS

I have installed django-cms in my hosting. But there is a problem. That's when I make syncdb, all my apps are synced, cms app is not. Although I have declared full enough in the settings. It is also not error at all. Someone help me. Thanks a lot! (1146, "Table '***.cms_page' doesn't exis...

26
голосов
8ответов
48270 просмотров

How do I override delete() on a model and have it still work with related deletes

I'm having a problem because I'm deleting a Widget by using some_widget_instance.delete(). I also have a model called WidgetFile with an override delete() method so that I can delete files off my hard drive when a WidgetFile is deleted. The problem I'm having is that if I delete a Widget, and it ...

25
голосов
5ответов
3649 просмотров

search functionality on multi-language django site

I'm building a multi-language Django site, and I'm using django-transmeta for my model data translations. Now I'm wondering if there is a Django search app that works with multi-language models. I've played with Haystack and it works fine for single-language sites, but I can't get it to work with...

2
голосов
2ответов
763 просмотров

Get records before and after current selection in Django query

It sounds like an odd one but it's a really simple idea. I'm trying to make a simple Flickr for a website I'm building. This specific problem comes when I want to show a single photo (from my Photo model) on the page but I also want to show the image before it in the stream and the image after it...

15
голосов
3ответов
4501 просмотров

How do I memoize expensive calculations on Django model objects?

I have several TextField columns on my UserProfile object which contain JSON objects. I've also defined a setter/getter property for each column which encapsulates the logic for serializing and deserializing the JSON into python datastructures. The nature of this data ensures that it will be acc...

2
голосов
1ответов
747 просмотров

List foreign keys linking to a model

How can I display objects that link to an object via a ForeignKey in Django (specifically in the admin interface). For example, if I click on an object, I'll not only see the object but also any other object that link to it. e.g. I have a model for "Manufacturer" and another one for "Model"...t...

1
голосов
2ответов
1182 просмотров

Django: How to modify a text field before showing it in admin

I have a Django Model with a text field. I would like to modify the content of the text field before it's presented to the user in Django Admin. I was expecting to see signal equivalent of post_load but it doesn't seem to exist. To be more specific: I have a text field that takes user input. I...

33
голосов
5ответов
20129 просмотров

What's the reason why Django has SmallIntegerField?

I'm wonder why it's provided. The field is database dependent, doesn't that make it totally unreliable to use? I want to store birth year in a model, kinda like class Person(models.Model): name = models.CharField(max_length=256) born = models.IntegerField() Of course this requires very li...

0
голосов
2ответов
81 просмотров

django query db on every request

i have a navigation element that is determined by values in a database. no matter what view it is, i need to get these navigation objects out of the database. where in the code can i tell it to set a template variable containing all the navigation objeccts without setting it in every view?

2
голосов
2ответов
735 просмотров

Django: How to access originating instance from a RelatedManager?

I would like to access the Foo instance foo within my manager method baz: foo.bar_set.baz() baz would normally take an argument of Foo type: BarManager(models.Manager): def baz(self, foo=None): if foo is None: # assume this call originates from # a RelatedM...

2
голосов
2ответов
2517 просмотров

Django model refactoring and migration

I'd like to refactor a number of django apps in a way which involves moving Models from one app into another where they can be more readily reused. A number of these models have either ForeignKey relationships or M2M relationships to other models (such as User). For example: class Department(...

1
голосов
2ответов
68 просмотров

Mashing and sorting 3 models in one data set

I've got three models that show some sort of activity on a website I'm making. Song, Vote and Comment. They all share a common column when which shows when a record was created. I want to show a list of activity based on all three models. In short I want to munge them together, sort by when, and...

2
голосов
2ответов
768 просмотров

Django Model in one to one relationship and displaying it from the admin

For the following models: class Price: cad = models.DecimalField(max_digits=8, decimal_places=2) usd = models.DecimalField(max_digits=8, decimal_places=2) class Product: name = models.CharField(max_length=255) price = models.ForeignKey(Price) For each product, it's related to ...