Tuesday, April 1, 2014

Filtersets

Hi All. I wonder if anyone can point me in the right direction. I am building a web api using django and FilterSets and wish to allow consumers to perform a query along the lines of

Manufacturer =x OR manufacturer = y etc etc

Is this achievable out of the box and how would you specify this within the url? My current url looks like this

http://127.0.0.1:8000/compare/api/instance/?Manufacturer=x&Manufacturer=y

but this only performs an AND on the underlying data

Manufacturer =x AND manufacturer = y etc etc

Also, please note that whilst I would like to perform an OR with regard to the manufacturer if I include other fields to be queried I would expect these to be AND'd for example

http://127.0.0.1:8000/compare/api/instance/?Manufacturer=x&Manufacturer=yModel=z

should equate to

(Manufacturer =x OR manufacturer = y) AND Model = z

Thanks In advance

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/67d84be9-8c09-4013-8ecd-552689cec383%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ManyToManyField and Multi Table Inheritance

Hi,

I've run into interesting issue and I'm not sure if I do something wrong or this is Django issue. I'm using Multi Table Inheritance:

<code>
from django.db import models
from django import forms

class AccountType(models.Model):
    users = models.ManyToManyField('auth.User', related_name='accounts')


class AccountTypeA(AccountType):
    name = models.CharField(max_length=255)


class AccountTypeAForm(forms.ModelForm):
    class Meta:
        model = AccountTypeA
        fields = ('name', 'users')
</code>

However, users are not saved in database. Find out that ModelForm calls `self.instance.users = <list-of-users>` but that's not get saved. Even 

<code>
account = AccountTypeA(name='something')
account.save()
account.users = User.objects.all()
</code>

is not propagated. However, account.accounttype.users works perfectly fine. Do I do something wrong?

P.S: I'm using Django 1.6

Izidor

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c9da2414-1a13-48df-bc59-d6ee498ae039%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: ManyToMany quick question

Below is my models.py
My problem is when I syncdb (I have dropped the db couple times to start over)
the country_name field with m2m never shows in the db. what am I doing wrong? I am using postgres

class Products(models.Model):

    hs_number = models.CharField(primary_key=True, blank=True, max_length=4)
    product_descript = models.CharField(max_length=250)

    class Meta:
        db_table = "Products"

    def __unicode__(self):
        return self.hs_number


class Countries(models.Model):
    country_id = models.CharField(primary_key=True, max_length=2, blank=True)
    country_name = models.ManyToManyField(Products, through="Imports", blank=True)
    region = models.CharField(max_length=200)

class Imports(models.Model):
    hs_number = models.ForeignKey(Products)
    country_id = models.ForeignKey(Countries)
    imported_value2008 = models.DecimalField(max_digits=12, decimal_places=2, default=0.00)
    imported_value2009 = models.DecimalField(max_digits=12, decimal_places=2, default=0.00)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8a196bda-12d8-4bfa-94d9-db4c6aefa491%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Django apps

Start here and follow the tutorial:

https://docs.djangoproject.com/en/1.6/intro/tutorial01/

Then you may want to run through this if you are interested in the goe stuff:

https://docs.djangoproject.com/en/1.6/ref/contrib/gis/tutorial/

That should give you a good idea on where to start with your own app


On Sunday, 30 March 2014 14:40:19 UTC+1, ngangsia akumbo wrote:
I wish to develope application that can give directions and location.

Pleas i need some guidance for a way forward. I have done some research but
still not getting it right. 

I need some guidance

Thanks

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/02c7e892-241f-482a-ab1d-09843e7b08d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Use custom HTML to render forms

On Tuesday, 1 April 2014 00:40:44 UTC+1, Fred DJar wrote:
HELP PLEASE

No.

You don't get to demand that people help you. If someone knows the answer to your question, and they have time to answer - and if they can work out what you're asking, which isn't obvious - they will reply. But if you want help on demand, you need to pay someone.
--
DR. 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/162b8220-9c99-4f7f-ad36-7701d6a40451%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Logging into django admin site via wget and/or wkhtmltopdf

same error is coming .....Have u solved this problem

On Thursday, March 4, 2010 4:17:48 PM UTC+5:30, Emma F wrote:
Has anyone ever had any success accessing the django admin site via
either of these tools?

I'm working on a view that will convert a particular dynamically-
generated page in my site to a PDF file, which can then be downloaded
from the server.  I originally tried to do this using this reportlab/
pisa method described in the documentation, but it couldn't cope with
the formatting required, so I'm on to plan B: wkhtmltopdf, run as a
command-line tool via subprocess.Popen in the django view.   If I
can't get that to work, I will have the view mirror the page with wget
(again using Popen) and then run wkhtmltopdf off that local copy on
the server.

Both methods work perfectly with a local copy of the page I've saved
from my browser. However, I'm having difficulties making it work
automatically from the view, with live pages from the application. I'm
trying to use the --post option of wkhtmltopdf to log in via the login
form and then convert the page.  I can get this method to work with
various other sites on the web, but something goes wrong when I try
with my django admin site.

I'm using the standard authentication that comes with the django admin
site, and on examing the code for the login form fields, it looks like
so:

<form action="/mysite/admin/" method="post" id="login-form">
        <input type="text" name="username" id="id_username" />
         <input type="password" name="password" id="id_password" />
          <input type="hidden" name="this_is_the_login_form"
value="1" />
         <input type="hidden" name="post_data" value="" />
         <input type="submit" value="Log in" />
 </form>

I've tried to translate the names and values of those fields into
wkhtmltopdf --post commands.  (I'm not too sure about the hidden
post_data field with the value of "", so that could be where the
problem lies: I've tried leaving it out altogether, leaving the second
argument to that --post blank, using "" and using + to stand in for a
space, but the result is always the same.)

Here's what I plug in:

wkhtmltopdf --post username myname --post password mypassword --post
this_is_the_login_form 1 --post post_data +[or whatever I'm using]
http://www.server.com/mysite/admin index.pdf

And the result is a pdf of a django debug page, telling me:

******************
     Exception Type: MultiPartParserError
     Exception Value: Invalid boundary in multipart: None
     Exception Location: /usr/local/lib/python2.5/site-packages/django/
http/multipartparser.py in __init__, line 65

******************

Using the alternative method - wget to try and mirror the file, I
translate the form like this:

wget -m --post-
data='username=myname&password=mypassword&this_is_the_login_form=1&post_data=
+'  http://www.server.com/mysite/admin

And get an "Error 500: Internal Server Error" method in the command
line.


Can anyone suggest what might be going wrong here - is it something to
do with the way I'm handling the hidden, valueless "post_data" form
field? Or something else I'm doing wrong?... Or is there some inherent
feature of the django admin authentication that is going to prevent
this process working?

Thank you to anyone who can help!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a5aad2ea-ff7a-4374-a25c-7f3f6319b8f1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Why can invalid models be saved?

Hi,

sorry for the newbie question!

In the admin I cannot create a user without a username, but on the shell it is possible:

>>> from django.contrib.auth.models import User
>>> u = User()
>>> u.save()
>>> u.id
2

I am trying to understand why this is possible. Does this mean model constraints in general are not enforced when instances are created and saved? Thus I will always have to validate my models before saving them, unless I set null=True on a field, in which case I'd expect to get an exception?

Thanks,
Claus

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4b097bd9-cc8b-4511-8efa-2fb4537b702f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.