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 ...
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 ...
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...
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...
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) / ...
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...
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?
...
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...
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...
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...
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 ...
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...
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 ...
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...
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 ...
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...
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:
...
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...
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.
...
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 %}
{...