django

Complex ordering in Django

So I am pulling a list of links and I am attempting to sort these links by popularity. I am using the Hacker News algorithm: Y Combinator's Hacker News: Popularity = (p - 1) / (t + 2)^1.5 Votes divided by age factor. Where p : votes (points) from users. t : time since submission in hours. p is subtracted by 1 to negate submitter's ...

Django - How to remove F() from a field?

Hello guys, after doing a query with F() (see http://docs.djangoproject.com/en/dev/topics/db/queries/#query-expressions), I save the object, but then, I need to save it again. I want to remove F() from the field. If I don't, F() gets called again. For example rank.ammountMatchesRanked = F('ammountMatchesRanked') + 1 rank.save() # does ...

When is the formfield() method called in Django?

This is a question on making custom fields in Django. I'm making a field called EditAreaField, which inherits from TextField. Here's what my code looks like: class EditAreaField(models.TextField): description = "A field for editing the HTML of a page" def formfield(self, **kwargs): defaults = {} defaults['widget'] = Ed...

How do I get one to many/foreign key to work in django?

Here is the code I've written: models.py: class Name_overall(models.Model): rank = models.IntegerField() name = models.CharField(max_length=50) frequency = models.IntegerField() def __unicode__(self): return self.name class Name_state(models.Model): gender = models.CharField(max_length=1, choices=GEND...

Implementing a popularity algorithm in Django

I am creating a site similar to reddit and hacker news that has a database of links and votes. I am implementing hacker news' popularity algorithm and things are going pretty swimmingly until it comes to actually gathering up these links and displaying them. The algorithm is simple: Y Combinator's Hacker News: Popularity = (p - 1) / ...

passing a value to an HttpResponse request

I have a urlpattern that brings a template that allows the fields of a model instance to be viewed: (r'^display/(?P<id>\w+)/', display_record), I also have a view function that allows a single instance to be edited. When the object is saved, it simply returns to the same template: if form.is_valid(): form.save() retur...

Why Django function django.views.static.serve() is insecure?

According to the Documentation using the django.views.static.server() function is: inefficient and insecure. I understand why it's inefficient, but in which aspect is it insecure? ...

How to get (and use) extended permissions in Facebook with Python/Django

I'm trying to write a simple app that lets a user grant my code permission to write to her page's Facebook stream. As I understand it, it should be as easy as: Have the user click on a button that launches a popup containing the a page in my Facebook app. In that page, they click on something that grants stream_publish to my app and a...

django admin actions on all the filtered objects

Admin actions can act on the selected objects in the list page. Is it possible to act on all the filtered objects? For example if the admin search for Product names that start with "T-shirt" which results with 400 products and want to increase the price of all of them by 10%. If the admin can only modify a single page of result at a tim...

Parse Facebook feed datetime in python?

I am reading a Facebook updates feed using the python library 'feedparser'. I loop through the collection of entries in my Django templates, and display the results. The updated field is returned in a big long string, of some format I am unfamiliar with. Tue, 01 Dec 2009 23:55:52 +0000 How can I... A) Use a Django filter to clean th...

Django: ForeignKey with choices=Customer.objects.filter(account=self.account)

class Ticket(models.Model): """ An order placed by a customer. """ account = models.ForeignKey(Account) client = models.ForeignKey(Client, choices=Client.objects.filter(account=self.account)) Obviously this wouldn't work because there is no instance available for 'self',but you can see what I'm trying to do here. I ...

Django: limit_choices_to (Is this correct)

Is this correct? class Customer(models.Model): account = models.ForeignKey(Account) class Order(models.Model): account = models.ForeignKey(Account) customer = models.ForeignKey(Customer, limit_choices_to={'account': 'self.account'}) I'm trying to make sure that an Order form will only display customer choices that belong...

Save it if this RECORD is not exist ?

Models.py #..... class FilterSave(models.Model): def __unicode__(self): return "%s" % (self.name) name = models.CharField(max_length=50) customer_type = models.CharField(max_length=20) tag = models.CharField(max_length=10) In my views.py #...... def save_filter(self, filter_name, keyword_filter): dict_json ...

loading sub-objects problem

Hi all, I have an object A that has two ForeignKey relations to objects B and C, and a ManyToMany relationship to object D. When I try to get an object of type A, say a = A.objects.get(id=1), it only returns me the forign keys of the sub-objects and doesn't load them automatically. In general I need to load all the sub-objects and ser...

To what framework is it worth to switch from django

The last framework, which I used, was Django. I enjoy a lot of things in that, like: The project structure is simple - there are not too many directories and files The admin interface Great documentation XML export-import The concept of Form objects: after you define a form, you can display the form in 1 line, you can even make a form ...

My path to learn Python/Django...

I began learning Python with Dive into Python(I read some chapters), then I switched to Django using The Django Book and the Django Documentation. I made a simple web app, It worked fine but the code was a total mess. In order to improve my skills I began reading and coding the projects of Django Practical Projects (I've recently finish...

Is handling requests/accessing database in views a good practice?

I have a problem with django's MVC. I understand that this is not the traditional MVC, but the documentation emphasizes throughout that it indeed separates presentation from business logic. However, the tutorial comes to a piece of code like this: def vote(request, poll_id): p = get_object_or_404(Poll, id=poll_id) try: ...

Django: Pagination in generic views?

Hi, This is in my urls.py: group_info = { 'queryset': Group.objects.all(), 'template_object_name': 'groups', 'paginate_by': 25, } And this is the relevant URL: (r'^groups/$', 'django.views.generic.list_detail.object_list', group_info), And this is my code in the template: <div class="pagination"> <span class="st...

Django-registration - some activation

Hi. How can I force resending activation e-mail to user? E.g. when he accidentaly deletes the mail, he clicks in link in my website, and django will send him new activation e-mail. ...

django's UserCreationForm problem

Hi, I have got problem with django's UserCreationForm. It's very strange because ween I: view: from django.contrib.auth.forms import UserCreationForm from django.shortcuts import render_to_response form = UserCreationForm() context = {'form' : form} render_to_response('something.html', context) template: ... {% block content %} {...