django

django variable passing

I have a page that I'm rendering with Django call it example.html. In example.html I have some code that is something like {{ MyObject.Attribute }} How do I get MyObject to be passed into the page so that I can display it? I know that it's in urls.py, but I'm not exactly sure how it works. ...

select_related across many to many fields in django or how do i access many to many fields using .all()

i'm writing a data migration using south... but the question refers to the use of select_related to retrieve many to many fields. the documentation specifies that select_related can be used for fields with relationships using ForeignKey ... i can't fathom it wont' work with ManyToMany fields right? my field have blank=null but the docu...

python classes that refer to each other

I have two classes that refer to each other, but obviously the compiler complains. Is there any way around this? EDIT Actually my code is slightly different than what Hank Gay uses. So python can definitely deal with some kinds of circular references, but it tosses an error in the following situation. Below is what I've got and I ge...

python observer pattern

I'm new to python but I've run into a hitch when trying to implement a variation of the observer pattern. class X(models.Model): a = models.ForeignKey(Voter) b = models.CharField(max_length=200) # Register Y.register(X) This doesn't seem to work because it says X is not defined. A couple of things are possible: A) ...

Filtering a Class and Subclass in Django

I have a project with an FAQ app. The app has models for FAQ (written by the site authors) and UserFAQ (written by users-- not just a clever name). I want to return all entries, FAQ or UserFAQ that match certain conditions, but I also want to exclude any UserFAQs that don't match a certain criteria. Ideally, it would looks something like...

Django: what does "load" do (in a template file)?

As "load" is far too generic for searching: What is the purpose of "load" and what does it do in this particular case? - in a template file, base_weblog.html, {% load weblog %}{% render_month_links %} Are some naming conventions used in order for "load" to do its job? E.g. names of folders and/or files and/or class names? Where is t...

How to sort on number of visits in Django app?

In Django (1.0.2), I have 2 models: Lesson and StatLesson. class Lesson(models.Model): contents = models.TextField() def get_visits(self): return self.statlesson_set.all().count() class StatLesson(models.Model): lesson = models.ForeignKey(Lesson) datetime = models.DateTimeField(default=datetime.datetime.now()) ...

How to make a customizable user survey in Django.

I am making a system for a company which among other things must hold information about the satisfactory level about various things, I have made it work fine using a fixed model with fixed questions and answers, but I am sure that they will need to change or add questions. So I want to make a system where users can make custom evaluatio...

Display row count from another table in Django

Hello. I have the following classes in my models file class HardwareNode(models.Model): ip_address = models.CharField(max_length=15) port = models.IntegerField() location = models.CharField(max_length=50) hostname = models.CharField(max_length=30) def __unicode__(self): return self.hostname class Subscripti...

Has anyone got django_clickpass working

Am having a number of problems implementing the code from the Washington Post site and they are not providing suppport. Looks like an excellent tool so am persisting but would welcome any tips from those who have gone before. http://opensource.washingtontimes.com/projects/django-clickpass/ Current error is: Exception Value: (1048, "...

Unable to find/build a commenting system similar as at Djangobook

I want to open-source my notes similarly as at DjangoBook. I have not found any similar open-source system as at the website. I am particularly interested in the vertical commenting system. This suggests me that I need to build one by myself for open-source. How would you build a similar commenting system as at the website? ...

Dynamic User Menu in Django

Is there a way to have a user menu that'll change according to the permissions assigned to the user group a user belongs to? I'm thinking of something that checks for these permissions at the view level, and also removes menu options a user doesn't have permission to. ...

django refactoring models

I've been doing a little clean up on my django project and so I decided to rename some models remove some unnecessary fields etc. I dropped all the tables from the dbase and reran "syncdb". However, now I'm getting and error Could not import pollsite.polls.views. Error was: cannot import name OldTableName Its a template error from b...

Why on earth do I have to pass RequestContext in all of my responses?

I want to highlight the current page in the navigation menu. Obviously I need to give the menu links a class like 'active' when you are on their page. This is a classic problem and I've seen many solutions proposed. My problem is I hate all of them and consider none of them to be very DRY. For example: @register.simple_tag def active(re...

Get user group in a view

I want to display a menu that changes according to the user group of the currently logged in user, with this logic being inside of my view, and then set a variable to check in the template to determine which menu items to show....I'd asked this question before, but my logic was being done in the template. So now I want it in my view......

Django - how to let one application reference another

Hello, i have two Django apps in my Project, call them App1 and App2. App1 is the "Home"-application that displays a text to introduce users and shows some news. App2 is a "Content"-app to display pages that only consist of a title and some html retrieved from the DB. I want App1 to display it's text using the model from App2. I can do ...

Can you access a subbed-classed model from within the super-class model in the Django ORM?

Lets say I have model inheritance set up in the way defined below. class ArticleBase(models.Model): title = models.CharField() author = models.CharField() class Review(ArticleBase): rating = models.IntegerField() class News(ArticleBase): source = models.CharField() If I need a list of all articles regardless of type ...

Met a problem when runnning in dreamhost, django + mysql, can someone help look?

ProgrammingError at /account/register/ (1110, "Column 'about' specified twice")Request Method: POST Request URL: http: Exception Type: ProgrammingError Exception Value: (1110, "Column 'about' specified twice") Exception Location: /home/temp/lib/python2.6/site-packages/MySQL_python-1.2.3c1-py2.6-linux-x86_64.egg/MySQLdb/connections.py...

Locking and Synchronization in DJango

I am a little new to DJango and I am not quite sure how to handling locking of critical sections. I know Python has some great thread locking mechanisms I can use, but I don't know how well Django will support it. Will a production server fork multiple processes each with a container running my code, or will it just be in one container...

Modeling a complex relationship in Django

I'm working on a Web service in Django, and I need to model a very specific, complex relationship which I just can't be able to solve. Imagine three general models, let's call them Site, Category and Item. Each Site contains one or several Categories, but it can relate to them in one of two possible ways: one are "common" categories, wh...