django

Forced to use inconsistent file import paths in Python (/Django)

Hi I've recently been having some problems with my imports in Django (Python)... It's better to explain using a file diagram: - project/ - application/ - file.py - application2/ - file2.py In project/application/file.py I have the following: def test_method(): return "Working" The problem occurs in proj...

Django Double Escaping Quotes etc.

I'm experiencing what I would consider somewhat strange behavior. Specifically if I have a string like this: 1984: Curriculum Unit by Donald R. Hogue, Center for Learning, George Orwell "A center for learning publication"--Cover. It results in the following after being auto-escaped by the Django template s...

django - QuerySet recursive order by method

I may have a classic problem, but I didn't find any snippet allowing me to do it. I want to sort this model by its fullname. class ProductType(models.Model): parent = models.ForeignKey('self', related_name='child_set') name = models.CharField(max_length=128) def get_fullname(self): if self.parent is None: ...

How can I integrate photos from flickr into my web-site using Django

Is there a tutorial or sample-code out there? ...

Sending localized messages to Django users

I'm having trouble with sending localized messages to Django users using the user.message_set.create(message="Message") mechanism. First of all, user.message_set.create(message=_("Message")) flat out doesn't work, SQLite says it won't accept the non-ascii parameter (localized message contains special characters). user.message_se...

removing <ul> from django forms validation errors

In Django the {{ form.field.errors }} gives the validation error for a field. But it always displays it as unordered list (). But I just want the error message. Is there a way to get the error message? ...

Django - send email on model change.

I want to send an email when a specific field is changed in a model. Is it possible? Here is what I am looking for. I have a profile model that includes a BooleanField that when the administrator selects to be true I want to send user an email. I know I could put it in a "def save(self):" but, that fires off an email anytime the mod...

How to make email field unique in model User from contrib.auth in Django

I need to patch the standard User model of contrib.auth by ensuring the email field entry is unique: User._meta.fields[4].unique = True Where is best place in code to do that? I want to avoid using the number fields[4]. It's better to user fields['email'], but fields is not dictionary, only list. Another idea may be to open a new ti...

Show related inlines in the admin on form of model with GenericForeignKey.

I have simple models with generic relations from this example at the Django Project: class Image(models.Model): image = models.ImageField(upload_to="images") class ImageLink(models.Model): image = models.ForeignKey(Image) content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content...

models.py getting huge, what is the best way to break it up?

Directions from my supervisor: "I want to avoid putting any logic in the models.py. From here on out, let's use that as only classes for accessing the database, and keep all logic in external classes that use the models classes, or wrap them." I feel like this is the wrong way to go. I feel that keeping logic out of the models just to ...

How to use schemas in Django?

I whould like to use postgreSQL schemas with django, how can I do this? ...

Django - last insert id

I can't get the last insert id like I usually do and I'm not sure why. In my view: comment = Comments( ...) comment.save() comment.id #returns None In my Model: class Comments(models.Model): id = models.IntegerField(primary_key=True) Has anyone run into this problem before? Usually after I call the save() method, I have acces...

Add data to Django form class using modelformset_factory

I have a problem where I need to display a lot of forms for detail data for a hierarchical data set. I want to display some relational fields as labels for the forms and I'm struggling with a way to do this in a more robust way. Here is the code... class Category(models.Model): name = models.CharField(max_length=160) class Item(mod...

Django - finding the extreme member of each group

I've been playing around with the new aggregation functionality in the Django ORM, and there's a class of problem I think should be possible, but I can't seem to get it to work. The type of query I'm trying to generate is described here. So, let's say I have the following models - class ContactGroup(models.Model): .... whatever .....

limit output from a sort method

if my views code is: arttags = sorted(arttags, key=operator.attrgetter('date_added'), reverse=True) what is the argument that will limit the result to 50 tags? I'm assuming this: .... limit=50) is incorrect. more complete code follows: videoarttags = Media.objects.order_by('date_added'),filter(topic__exact='art') audioarttags =...

How can you use two different versions of Django for different projects on the same machine?

I'm currently using Django 1.0 on my Mac OS X 10.5.7 box. It's installed to: /Library/Python/2.5/site-packages/django/ However, there are features that are part of the development release (1.1) of django that I'd love to use for internal tools at my company. Unfortunately I can't just update to the development version because I still n...

How would you model this database relationship?

I'm modeling a database relationship in django, and I'd like to have other opinions. The relationship is kind of a two-to-many relationship. For example, a patient can have two physicians: an attending and a primary. A physician obviously has many patients. The application does need to know which one is which; further, there are cases w...

Authenticated commenting in Django 1.1?

(Now that Django 1.1 is in release candidate status, it could be a good time to ask this.) I've been searing everywhere for ways to extend Django's comments app to support authenticated comments. After reading through the comments model a few times, I found that a ForeignKey to User already exists. From django.contrib.comments.models: ...

Django admin custom javascript load order

I am using jquery to add a few features onto some fields in the django admin, inlcuding my code by using something like the following: class SomeAdmin(admin.ModelAdmin): class Media: js = ( "/static/js/lib/jquery-1.3.2.min.js", "/static/js/admin/app/model.js" ) ... .. . ...

Can I copyright and license under GPL3 models.py views.py files generated by django v 1.0.2?

After I've added my own code to models.py, views.py and other files generated by django, can I protect them using the GPL? Or is there a clash given there is code in there that has been auto generated by django which is not licensed under GPL? ...