django

What is the proper way to address permissions?

I added a new model with one permission, and now I need to add that permission to a few users on the production machine after deploying the code and running syncdb for the new app involved. I haven't found the correct way to do this. The auth docs mention User.user_permissions.add(permission), but never tell me what 'permission' is or th...

Django set default form values

I have a Model as follows class TankJournal(models.Model): user = models.ForeignKey(User) tank = models.ForeignKey(TankProfile) ts = models.IntegerField(max_length=15) title = models.CharField(max_length=50) body = models.TextField() I have a modelform as follows for that model class JournalForm(ModelForm): tank = forms...

how to nginx virtual servers + fcgi for django?

I would like to run several virtual hosts via nginx, each serving a different django app via fcgi. Is this possible? If so, does anyone have good resources on where/how to start? The nginx docs seem to be mostly examples, but none of the particular config I'm attempting... ...

Django: Querying read-only view with no primary key

class dbview(models.Model): # field definitions omitted for brevity class Meta: db_table = 'read_only_view' def main(request): result = dbview.objects.all() Caught an exception while rendering: (1054, "Unknown column 'read_only_view.id' in 'field list'") There is no primary key I can see in the view. Is there a wo...

memcached caches request?

Hi there, after caching several views on my django project -@cache_page(60 * 5)- I've noticed that memcached caches the entire view, even the request argument! So if the first user that visits a page is logged in as userxyz, all other anonymous or registered users that will ask the same page will be presented with the page that was cach...

Model and Validation Confusion - Looking for advice

I'm somewhat new to Python, Django, and I'd like some advice on how to layout the code I'd like to write. I have the model written that allows a file to be uploaded. In the models save method I'm checking if the file has a specific extension. If it has an XML extension I'm opening the file and grabbing some information from the file to ...

Django Override form

Another question on some forms Here is my model class TankJournal(models.Model): user = models.ForeignKey(User) tank = models.ForeignKey(TankProfile) ts = models.IntegerField(max_length=15) title = models.CharField(max_length=50) body = models.TextField() Here is my modelform class JournalForm(ModelForm): tan...

Django email

I am using the Gmail SMTP server to send out emails from users of my website. These are the default settings in my settings.py EMAIL_HOST = 'smtp.gmail.com' EMAIL_HOST_USER = '[email protected]' EMAIL_HOST_PASSWORD = 'pwd' EMAIL_PORT = 587 EMAIL_USE_TLS = True SERVER_EMAIL = EMAIL_HOST_USER DEFAULT_FROM_EMAIL = EMAIL_HOST_USER If I...

django / file uploads permissions

Hi there, I wrote a django app, but i have a little problem with the file permissions of the uploads files from a web form. Baically i can upload a .mp3 file but it always keep chmod 600. Th container folder has chmod 775, and the umask is set to 022. I'm in a shared hosting service. Thanks if any one can give a clue. ...

django- run a script from admin

I would like to write a script that is not activated by a certain URL, but by clicking on a link from the admin interface. How do I do this? Thanks! ...

django admin inlining foreign key issue

Ok, I'm sure I'm missing something stupidly simple, since nobody else seems to be asking the same question. Either way, the problem's annoying me, so I'll suck up my pride and just ask it. I'm mainly just playing around right now with creating a simple Training/Testing application. For starters, I need to be able to create a quiz type ap...

How to add a Manager from Field

What i want to do is when some model use my field, it will automaticaly add custom manager to that model. As far as i know, contibute_to_class provide such functionality class MyCustomField(CharField): def contribute_to_class(self, cls, name): super(MyCustomField, self).contribute_to_class(cls, name) setattr(cls, 'c...

Charts in django Web Applications

I want to Embed a chart in a Web Application developed using django. I have come across Google charts API, ReportLab, PyChart, MatPlotLib and ChartDirector I want to do it in the server side rather than send the AJAX request to Google chart APIs, as I also want to embed the chart into the PDF. Which is the best option to use, and what...

Django MPTT - tree filtering

I am using MPTT's templatetag to render my genre tree. {% for genre, structure in genres|tree_info %} {% if tree.new_level %}<ul><li>{% else %}</li><li>{% endif %} {{ genre.name }} {% for level in tree.closed_levels %}</li></ul>{% endfor %} {% endfor %} The thing is, my genre object has is_visible property w...

Appropriate placement for my testcases belonging to a non-app in Django

I have built my website in Django. And like any other django project I have got apps inside the project root directory and some special folders like(extensions a.k.a custom django command extensions). With an app, we dont have any problem with having testcases. "tests.py" inside the app directory will be the solution. But for a special f...

django inner join query

I am working with django and having a hard time grasping how to do complex queries Here is my model class TankJournal(models.Model): user = models.ForeignKey(User) tank = models.ForeignKey(TankProfile) ts = models.DateTimeField(auto_now=True) title = models.CharField(max_length=50) body = models.TextField() cla...

How to get './manage.py syncdb' to create additional views or run custom SQL?

Is there a way to run some custom SQL statements after syncdb does it thing creating the tables for the models? Specifically, I would like to create some database views. Thanks in advanced. ...

Newbie Django Question : Going crazy with a form for creating and updating

OK. I just tied myself in a knot trying to make a form in Django which I can use to either enter data about a new record or update an existing one. Can anyone sketch out the right things I should have in my forms, views and urls if have this model? : class Person(models.Model) : name = models.CharField() age = models.IntegerField(...

Django Model Inheritance. Hiding or removing fields.

I want to inherit a model class from some 3rd party code. I won't be using some of the fields but want my client to be able to edit the model in Admin. Is the best bet to hide them from Admin or can I actually prevent them being created in the first place? Additionally - what can I do if one of the unwanted fields is required? My first ...

Django 1.0/1.1 rewrite of self join

Is there a way to rewrite this query using the Django QuerySet object: SELECT b.created_on, SUM(a.vote) FROM votes a JOIN votes b ON a.created_on <= b.created_on WHERE a.object_id = 1 GROUP BY 1 Where votes is a table, object_id is an int that occurs multiple times (foreign key - although that doesn't matter here), and created_on whic...