django

Django models: Why the name clash?

Firstly, I know how to fix the problem, I'm just trying to understand why it's occuring. The error message: users.profile: Reverse query name for field 'address' clashes with related field 'Address.profile'. Add a related_name a rgument to the definition for 'address'. And the code: class Address(models.Model): country = fie...

Django ManyToMany filter()

I have a model: class Zone(models.Model): name = models.CharField(max_length=128) users = models.ManyToManyField(User, related_name='zones', null=True, blank=True) And I need to contruct a filter along the lines of: u = User.objects.filter(...zones contains a particular zone...) It has to be a filter on User and it has...

What's wrong here? Iterating over a dictionary in Django template

I'm trying to iterate over a dictionary of model values in a Django template - I want to list the verbose_name of each model field alongside its value. Here's what I have in models.py: class Manors(models.Model): structidx = models.IntegerField(primary_key=True, verbose_name="ID") county = models.CharField(max_length=5, nu...

Many2ManyField is not saving via Modelforms

I have a Modelform: class POwner4NewModel(ModelForm): class Meta: model = ProductOwner exclude = ("o_owner","o_owner_desc","o_product_model","o_main_image","o_thumbnail","o_gallery_images","o_timestamp","o_status") This is the model's schema: class ProductOwner(models.Model): o_owner = models.ForeignKey(User, ...

NoReverseMatch error in django app

I am receiving this error in one of my templates and cant seem to figure out what's wrong. `NoReverseMatch: Reverse for 'getimagefile' with arguments '(12L, 'afN9LRzESh4I9CGe6tFVoA==\n')' and keyword arguments '{}' not found. My urls.py contains: urlpatterns = patterns('myproj.myapp.views', url(r'^getimage/(?P<extractedcontent_id>...

Custom filterspecs for auth.user

All the techniques I've seen for adding custom filterspecs to the Django admin involve editing models.py (eg link text) I'm customizing auth.user by registering my own ModelAdmin and would like to add some custom filterspecs. I could fake filterspecs in the template but I'd rather use custom filterspecs. Is there any way I can monkey-pa...

Django: What's an awesome plugin to maintain images in the admin?

I have an articles entry model and I have an excerpt and description field. If a user wants to post an image then I have a separate ImageField which has the default standard file browser. I've tried using django-filebrowser but I don't like the fact that it requires django-grappelli nor do I necessarily want a flash upload utility - can...

Right way to return proxy model instance from a base model instance in Django ?

Say I have models: class Animal(models.Model): type = models.CharField(max_length=255) class Dog(Animal): def make_sound(self): print "Woof!" class Meta: proxy = True class Cat(Animal): def make_sound(self): print "Meow!" class Meta: proxy = True Let's say I want to do: animals =...

Django: Save User ID with Model Save

My question is very similar to this question: http://stackoverflow.com/questions/862522/django-populate-user-id-when-saving-a-model Unfortunately I did not quite understand their answer. When a user logs in I want them to be able to submit a link and I have a user_id foreign key that I just can't seem to get to populate. def submit(r...

Python properties: Two instances of variable?

Really confused about what's going on here. I have a class defined as follows: class Profile(models.Model): user = models.OneToOneField(User) primary_phone = models.CharField(max_length=20) address = models.ForeignKey(Address) @property def primary_email(self): return self.user.email @primary_email.setter de...

Django haystack doesn't add to Solr index. [Works with whoosh, fails with Solr]

During development I used whoosh as a backend, and now want to switch to solr. I installed solr, changed the settings, to HAYSTACK_SEARCH_ENGINE, and HAYSTACK_SOLR_URL. Now when I try to update or rebuild the index it fails with Failed to add documents to Solr: [Reason: None] . All searches are also wrong with 0 results returned for ...

build website for mobile and pc with django

I am trying to develop a website for mobile and pc browser with django. and I am trying to figure out a best structure of the views and templates. there is what I have tried: 1) use different url ( like http://example.com/mobile/ and http://example.com/ OR http://example.com/?c=mobile ) to distinguish mobile and pc, and map them to d...

writing to data to excel

Hello, I have data that I need to export to excel, I just don't know how to go about it, here's the view I'm using, I've commented out my attempts.A push to the right direction will be greatly appreciated. def month_end(request): """ A simple view that will generate a month end report as a PDF response. """ current_dat...

Does Django have `__not_equal`?

Does Django have a field lookup like __not_equal? (Field lookups are __exact, __contains, etc.) ...

Django: Can't set ForeignKey value to None from admin

I have a model Category which has a ForeignKey to a SimplePage model. null and blank are set to True. The problem is, when I edit a Category from the admin interface, I can't change the ForeignKey to --------- (Which looks like the admin's way of saying None.) The value can be None initially, and I can change it to an actual value throug...

Why doesn't this loop display an updated object count every five seconds?

I use this python code to output the number of Things every 5 seconds: def my_count(): while True: print "Number of Things: %d" % Thing.objects.count() time.sleep(5) my_count() If another process generates a new Thing while my_count() is running, my_count() will keep printing the same number, even though it ...

get first related object in template

Hay all, I'm having difficulty accessing the first related object within a template. I'm using {{ course.student_set.all[0].get() }} but its throwing loads of errors. How do i get the first related object? Thanks ...

Object wont update

Hay all, my object doesnt seem to update when i call the save() method heres my code car = Car.objects.get(pk=car_id) car.views += 1 car.save() and the model views = models.FloatField(max_length=1000) I do have a save() override method, could this cause a problem? def save(self): d = timedelta(days=self.expires_in...

Django admin inline form error

Hi. I have an inline formset in my admin site. I also have save_as = True in admin.py. My models are, for example: class Poll(models.Model): question = models.CharField(max_length=200, unique = True) pub_date = models.DateTimeField('date published') class Choice(models.Model): poll = models.ForeignKey(Poll) choice = mod...

Django foreign keys

Hello, I am new to Django and I have the following relation in the model class Name_Mapping(models.Model): AccessionID = models.ForeignKey(('Feature', 'Protein', 'Substrate'), primary_key = True) Element_Name = models.CharField(max_length = 40) This raises an error: AssertionError: ForeignKey(('Feature', 'Protein', 'Substrate')...