django

Django - how to determine if model class is abstract

If a django model is made abstract, like below, is there a way to inspect the class to determine that it is abstract? class MyModel(models.Model): class Meta: abstract = True I would expect that I could examine MyModel.Meta.abstract, but according to Django docs: Django does make one adjustment to the Meta class of an abstra...

How to count and display objects in relation ManyToMany in Django

Hi! I have a simple model with news and categories: class Category(models.Model): name = models.CharField() slug = models.SlugField() class News(models.Model): category = models.ManyToManyField(Category) title = models.CharField() slug = models.SlugField() text = models.TextField() date = models.DateTimeFie...

Listing blog entries by year,month

Hi! I want to do something like this: Entries.objects.values('date.year','date.month') but this line is not valid. How can I list blog entries by year,month and display them in template? Thanks! ...

contact importer in python/django

Hello, I need to import contacts of given email id/pwd from gmail,yahoo,hotmail,etc,etc for python/django app. Please suggest? - Thanks, Aamir hussain ...

Is it possible to order_by with a callable?

DUPLICATE: http://stackoverflow.com/questions/981375/using-a-django-custom-model-method-property-in-orderby I have two models; one that stores posts and another that stores votes made on those posts, related using a ForeignKey field. Each vote is stored as a separate record since I need to track the user and datetime that the vote was...

Uploading image using flex and django

Hi, Anyone knows how to combine flex and django on upload images? I used fileRefenrece in Flex but I don't know how to relat it with a View in Django. Thanks! [EDIT] I'm using flex and django to make a site where people have an login e some data, like an mini an intern orkut. In the server-side i build my views, models etc, in the clie...

expand users table with django

I'm using the authentication that ships with django, and as such, it comes with its own SQL table. I have a few more attributes I'd like to use with the User model that are custom to my app such as a user photo or a random user blob where users can type in notes. what's the best way of extending the existing user table that ships with d...

Interacting with external DB via Django

I'm working on a Django app that interacts with an existing database (think ERP/transaction type data) to perform analysis. There will be minimal/no updating of the existing database mainly reading data in. Its just a simple small setup so no replication etc. issues to think about re. updating. The analysis would result in new records c...

Boolean fields in MySQL Django Models?

At Django, a boolean field in MySQL is stored as a TINYINT. When I retrieve it, I get 0 or 1. Shouldn't I get False or True? Is there a way to achieve this behaviour? ...

Problem with logic in Django template

Supose this portion of a Django template. regs is a list of Reg objects. Reg.editable is a BooleanField. I want to render a radio button per element in the list. If r.editable is False, the radio button must be disabled: {% for r in regs %} <input type="radio" value="{{ forloop.counter }}" {% if forloop.first %}checked="checked"{% endif...

NoReverseMatch in django

Hi. After debugging for a while I found what the error was, but I don't know how to fix it. I have an urlConf whit the name 'ver_caja' who receives as argument the id of a caja object, and then call the generic object_detail. The queryset is correct: get all the caja objects correctly. In the template I have the call: {% ver_caja caja...

Django: request.META['REMOTE_ADDR'] is always '127.0.0.1'

I have an application running with debug=True on a remote host somewhere. Now somehow every time I access REMOTE_ADDR it returns 127.0.0.1 no matter where the request is from. I'm not sure where to start and why this is happening. ...

How do I save to a field that is specified in a variable?

I want to do something like this: # models.py class Model(models.Model): name_in_my_model = models.CharField(max_length=100) # later fieldname = 'name_in_my_model' # this is what I want to do somehow: obj = Model.objects.get(pk=1) obj.fieldname = 'new name' obj.save() Is this possible? I'm making a reusable application, and ...

Updating global variable in django from external program

Application running in django, apache, python and mysql: I want to create global variable which I should be able to update from external python script may be using a cron job. The the solution I think of... is having a webpage which updates that variable and then call this through a python script. Any cleaner solutions? ...

Unique field values and ManyToMany relationships

Let's say I have a class structure that is defined below: Class Item(models.Model): ... price = models.IntegerField() upc = models.IntegerField() ... Class Store(models.Model): ... inventory = models.ManyToManyField(Item) ... Basically I want store models to have access to the same inventory. However the v...

How do I update an already existing row when using ModelForms?

Greetings, I have a question on how to update an existing row in my database when one of the fields is my primary key. I am using ModelForm and Django-Piston - my main goal here is to have RESTful Post send to my webservice. I am able to have initial Posts be sent correctly (i.e. that Primary key value doesn't exist yet). The problem is...

How do I create application scope variable django?

Hi, How can I create an application scope variable which is loaded when the django app starts, be in memory and accessible by all. Basically I want to reuse the variable through out the application without reloading it. Thanks ...

Configure MySQL to work with Django

Just installed Django (with easy_install) and created a project, but can't get mysql to work. python manage.py syncdb throws this error: ..... File "/Library/Python/2.6/site-packages/Django-1.1.1-py2.6.egg/django/db/backends/mysql/base.py", line 13, in <module> raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)...

SQL Compute the price of cart in one request

Hello, Typically, I have a really simple cart with some items in it, with a quantity. I wish to do something like this : SELECT SUM(price * quantity) as total FROM products WHERE product_id IN (1,2,3,4); But how can I bind the quantity with the product_id since quantity is not in the database ? Is there any other way to do this wit...

How do I expire a django template cache key on recieving a signal?

In my front page template I use the cache function like this: {% cache 86400 my_posts %} {% get_latest_posts %} {% endcache %} When there is a new post I would like to expire the cache key; like this: def clear_post_cache(): cache.delete('my_posts') post_save.connect(clear_post_cache, sender=Post) My problem is that the ca...