django

Generate a few models from existing database in Django

I know this exists django-admin.py inspectdb > models.py However, is there an easy way to limit it? Without manually deleting what I don't want. I'm connecting to a database that has over one hundred tables, but I only want models of about 4 or 5. Is there an easy way to generate models from a few given tables? They are quite big ta...

Django "comment_was_flagged" signal

Hello, This is my first time working with django signals and I would like to hook the "comment_was_flagged" signal provided by the comments app to notify me when a comment is flagged. This is my code, but it doesn't seem to work, am I missing something? from django.contrib.comments.signals import comment_was_flagged from django.core...

Refactoring a custom User model to user UserProfile: Should I create a custom UserManager or add user.get_profile() dozens of times?

I have been refactoring an app that had customized the standard User model from django.contrib.auth.models by creating a UserProfile and defining it with AUTH_PROFILE_MODULE. The problem is the attributes in UserProfile are used throughout the project to determine what the User sees. I had been creating tests and putting in this type ...

How hard is it to modify the Django Models?

I am doing geolocation, and Django does not have a PointField. So, I am forced to writing in RAW SQL. GeoDjango, the Django library, does not support the following query for MYSQL databases (can someone verify that for me?) cursor.execute("SELECT id FROM l_tag WHERE\ (GLength(LineStringFromWKB(LineString(asbinary(utm),a...

serving files using django - is this a security vulnerability

I'm using the following code to serve uploaded files from a login secured view in a django app. Do you think that there is a security vulnerability in this code? I'm a bit concerned about that the user could place arbitrary strings in the url after the upload/ and this is directly mapped to the local filesystem. Actually I don't think...

: in node causing Keyerror in xmlparsing using ElementTree

Hi I'm using ElementTree to parse out an xml feed from Kuler. I'm only beginning in python but am stuck here. The parsing works fine until I attempt to retrieve any nodes containing ':' e.g kuler:swatchHexColor Below is a cut down version of the full feed but same structure: <rss xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:kuler=...

Django pagination | get current index of paginated item in page index, (not the page index range itself)

I am trying to build a photo gallery with Django. It is set up by category. I have paginated the results of a category by n amount of images per page. I want to also use the paginator on the page that shows just the single image and have a prev/next button for the prev/next image in that category. My thought was to get the current i...

How do I do this Database Model in Django?

Django currently does not support the "Point" datatype in MySQL. That's why I created my own. class PointField(models.Field): def db_type(self): return 'Point' class Tag(models.Model): user = models.ForeignKey(User) utm = PointField() As you can see, this works, and syncdb creates the model fine. However, my curr...

Edit the opposite side of a many to many relationship with django generic form

I have two models: class Actor(models.Model): name = models.CharField(max_length=30, unique = True) event = models.ManyToManyField(Event, blank=True, null=True) class Event(models.Model): name = models.CharField(max_length=30, unique = True) long_description = models.TextField(blank=True, null=True) In a previou...

Django Form for date range

I am trying to come up with a form that lets the user select a date range to generate a web query in Django. I am having errors getting the date to filter with in my view, I am unable to strip the date. Here is my forms.py class ReportFiltersForm(forms.Form): start_date = forms.DateField(input_formats='%Y,%m,%d',widget=SelectDateWidg...

Django - How best to handle ValidationErrors after form.save(commit=False)

This is a fragment of my code from a view: if form.is_valid(): instance = form.save(commit=False) try: instance.account = request.account instance.full_clean() except ValidationError, e: # Do something with the errors here... I certainly don't want to do this 180 times. T...

How do I properly unit test a Django session?

The behavior of Django sessions changes between "standard" views code and test code, making it unclear how test code is written for sessions. Googling this yields two relevant discussions about this issue: Easier manipulation of sessions by test client test.Client.session.save() raises error for anonymous users I'm confused because b...

How do I write this query in Django?

Suppose I have a datetime column. "SELECT * FROM mytable WHERE thetime < INTERVAL 1 HOUR" How do you write this in Django? ...

figuring out objects created 30 min ago in django

I have a DateTimeField called created in my model and I would like to get all the objects where created date is 30 min or more. How would query this using MyModel.objects(....) in django? ...

how to write re-usable views in django?

These are the techniques that I use regularly to make my views reusable: take the template_name as an argument with a default take an optional extra_context which defaults to empty {} right before the template is rendered the context is updated with the extra_context for further re-usability, call any callable in extra_context.values(...

How do I use Django to insert a Geometry Field into the database?

class LocationLog(models.Model): user = models.ForeignKey(User) utm = models.GeometryField(spatial_index=True) This is my database model. I would like to insert a row. I want to insert a circle at point -55, 333. With a radius of 10. How can I put this circle into the geometry field? Of course, then I would want to check whic...

django model fields comparison

is there a way l can compare two columns | fields in django like Invoice.objects.filter(amountdue_lt=invoiceamount) where amountdue and invoiceamount are two columns of Invoice object Thanks ...

How do I write this insert statement in Django?

newthing = Link(user=request.user,last_updated=datetime.datetime.now()) However, this uses datetime , not the MYSQL "now()". How can I use mysql's now()? ...

django send_mail from queryset

I am trying to use the django send_mail method. I am running into 2 issues, notably converting mail addresses from a list into a csv to be used in the recipients. The second issue is getting the list of user emails from the notifications model. my models class notifications(models.Model): notID = models.AutoField(primary_key=True) ...

How can I write this query in Django? (datetime)

| time_before | datetime | YES | MUL | NULL | | | time_after | datetime | YES | MUL | NULL | | the_tag = Tag.objects.get(id=tag_id) Log.objects.filter(blah).extra(where=['last_updated >'+the_tag.time_before, 'last_updated' < the_tag.time_after]) Ok. Basically, I have an object that's ca...