django

Send invitation emails on post_save or all at once in django view?

There's a requirement in a web app I'm building about the possibility of the user sending join invitations to his friends. These invitations are stored in the database through the Invitation model. The user can send multiple invitations at once. What do you think is more appropriate: sending all emails at once in the back end view or se...

Django modelform: is inline adding related model possible?

I really hope this is not a duplicate: I couldn't find anything but that could just mean I'm not good at searching :) I have a Django app, and the staff is already using the admin app for... well, administration purposes. I also created a quick data entry page for a specific model, created substantially by dropping a modelform inside th...

How to write dynamic Django models?

Hi, what i want, is to receive advices to define a re-usefull Product model, for a shopping site app, nowadays I know that the store is going to commerce with "clothing", so the product model will have a "season or collections" relationship, but in the future I should use that app to commerce with X product, e.g: "cars" which have "mecha...

How to configure settings file to recognize translation.py, when using django-modeltranslation

I have begun testing django-modeltranslation and cannot seem to get my translation.py file recognized. Getting a "no translation.py found in the project directory" msg when running the sqlall command. I have the following: modeltranslation residing in /Users/judy/project a project called andor in /Users/judy/project a translation.p...

Django: setting required=True on formfield when running clean() .. actually just before

Hi all, I'm trying to force a form field to be required based on a choice widget during validation. def clean(self): cleaned_data = self.cleaned_data if cleaned_data.get('periodical') == True: if cleaned_data.get('period_start_date') == None: msg = _('custom message') self._errors['period_start_d...

Using a method in a model to count objects filtered by the primary key.

I wanted to use a method as part of my model to count all the occurrences of the object in another table that references it as a foreign key. Will the below work? class Tile(models.Model): #... def popularity(self): return PlaylistItem.objects.filter(tile__exact=self.id).count() And the relevant information from the p...

Return function as a field on django model

I have a model which have a function to calculate the difference between two fields Example: Class MyModel(models.Model): fieldA = models.FloatField() fieldB = models.FloatField() def delta(self): return self.fieldA - self.fieldB Id like to use this model in a GenericView. I can use the function delta as an extraC...

How to find resource intensive queries in Django

How to find the execution time for various Model API Calls in Django. ...

How to use Django templatetags in static media files?

Hi, Im using a flash gallery and the settings xml file is stored in /media/xml/gallery.xml In the gallery.xml file I want to add this snippet of code: <items> {% for image in images %} <item source="{{ MEDIA_URL }}{{ image.image }}" thumb="" description="{{ image.title }}" /> {% endfor %} </item> But the source="... rend...

Django unable to open sqlite on SOME queries only?

I have had no troubles locally, but pushing a new project to an existing machine (one running plenty of other django apps without trouble) gave this: OperationalError: unable to open database file What is more perplexing is: The sqlite file is read-write for all This error only happens on some queries! Other's are fine. In a fresh d...

"Save as" and "Save and add another" in Admin

Hi. Is there a way to have both "save as" and "save and add another" in django admin site? ...

web ERP in django where do i start??

I'm a computer science student doing my bachelor's degree. i'm interested in doing an simple application like an ERP in django. I've got about a month of time don't know where do i start. please do give in your opinion. ...

Disconnect signals for models and reconnect in django

I need make a save with a model but i need disconnect some receivers of the signals before save it. I mean, I have a model: class MyModel(models.Model): ... def pre_save_model(sender, instance, **kwargs): ... pre_save.connect(pre_save_model, sender=MyModel) and in another place in the code i need something like: a = MyMo...

Django runserver performance problem on localhost

Hi, I have a strange problem in Django development environment. I have changed my ISP and my setup is as follows: ISP -> Modem -> WirelessRouter -> Desktop (connected wirelessly) When I start my development enviornment and access the env http://localhost:8000, the performance is horrible, each request takes couple of around 10 second...

Serving files with Django and lighttpd

I'm trying to create a simple way of serving downloadable content with Django. The idea is that logged in users shall be able to download (rather large) files through lighttpd. There are several posts about this here on SO and I came also across a blog post with a simple solution. I created a view as in the abovementioned link (and add...

django dynamic Q objects in generic view

Hi, I want to be able to pass a variable caught in the URL to a Q object for a generic view. I created a generic view which is imported as my_views.view which handles things like pagination, sorting, filtering etc... I need to use Q objects because for some pages there will need some OR filters. Each page will also be filtering based o...

Help with designing models for a Django 'Project' app with 1 or more urls in it (variable), with editing at once in admin interface

Hello, i'm building a simple app for Django and I'm facing some problems with my models design, and the use of 'inlines' in the administration interface. The app is to manage projects. A project consists of a name, a description, other fields (e.g. tags...) and of multiple urls (like project url, source code repository url) but the num...

Is this how a modern news site would handle it's sql/business logic?

Basically, the below image represents the components on the homepage of a site I'm working on, which will have news components all over the place. The sql snippets envision how I think they should work, I would really appreciate some business logic advice from people who've worked with news sites before though. Here's how I envision it: ...

Validating data in Django ModelForm

And i have a simple modelform for Package from models import Package from django import forms class PackageForm(forms.ModelForm): class Meta: model= Package fields= ['name', 'version', 'url', 'description', 'arch', 'dependancies', 'conflicts', 'file'] How can i ask the modelform to check, within validation, if the file extens...

Dynamically select database based on request

I'm trying to keep my RESTful site DRY, and I can't come up with a good way to factor out the code to dynamically select from each "user's" separate database. We've got a separate database for each client. This comes in as a part of the URL, and is passed into each view as a keyword arg. I want to give each and every view the behavior of...