Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-03 Thread Furbee
You can set up an index on multiple field, as well, so if you’re searching
for As without a reference from B or C, using the index_together operative
in the class Meta for that model. I’m not completely sure, but I think this
may speed up you query time.

Thanks,

Furbee

On Saturday, February 3, 2018, Vijay Khemlani  wrote:

> Well, you should've said that in the first post.
>
> First I would try with a saner DB (Postgres)
>
> Also I don't think 300 ms is particularly bad, but in that case start
> looking into caching alternatives (e.g. memcached) or a search index (e.g.
> ElasticSearch)
>
> On Sat, Feb 3, 2018 at 3:14 AM, Web Architect  wrote:
>
>> Hi Furbee,
>>
>> Thanks for your response.
>>
>> With my experience I have always noticed that a query within query kills
>> the mysql and Mysqld CPU usage hits the ceiling. I would still check your
>> alternate.
>>
>> I have mentioned the size of A and B in response to Vijay's reply.
>>
>> On Saturday, February 3, 2018 at 1:06:48 AM UTC+5:30, Furbee wrote:
>>>
>>> There are a couple options you could try to see which is the best fit
>>> for your data. With DEBUG=True in settings.py you can check the actual
>>> queries and process time. It depends on the sizes of A and B. Another query
>>> you can run is:
>>>
>>> A.objects.exclude(id__in=B.objects.all().values_list('a_id', flat=True))
>>>
>>> When I tried, it seemed to be about the same speed with my test data as
>>> the one you had A.objects.filter(bs__isnull=True).
>>>
>>> To see what queries are generated and the query time with DEBUG=True:
>>> Open your Django Python Shell
>>> >>> A.objects.exclude(id__in=B.objects.all().values_list('a_id',
>>> flat=True))
>>> >>> A.objects.filter(bs__isnull=True)
>>> >>> from django.db import connection
>>> >>> for q in connection.queries:
>>> >>> print("{0}: {1}".format(q['sql'], q['time']))
>>>
>>> This will show you both queries generated and how long it took to get a
>>> response from your DB.
>>>
>>> You can also write raw SQL, if you can make one more efficiently.
>>>
>>> Furbee
>>>
>>> On Fri, Feb 2, 2018 at 10:56 AM, Vijay Khemlani 
>>> wrote:
>>>
>>>> "with large of records in A and B, the above takes lot of time"
>>>>
>>>> How long? At first glance it doesn't look like a complex query or
>>>> something particularly inefficient for a DB.
>>>>
>>>> On Fri, Feb 2, 2018 at 11:31 AM, Andy  wrote:
>>>>
>>>>> not that i know of
>>>>>
>>>>>
>>>>> Am Freitag, 2. Februar 2018 15:28:26 UTC+1 schrieb Web Architect:
>>>>>>
>>>>>> Hi Andy,
>>>>>>
>>>>>> Thanks for your response. I was pondering on option a before posting
>>>>>> this query thinking there could be better ways in django/SQL to handle
>>>>>> this. But now I would probably go with a.
>>>>>>
>>>>>> Thanks.
>>>>>>
>>>>>> On Friday, February 2, 2018 at 7:50:53 PM UTC+5:30, Andy wrote:
>>>>>>>
>>>>>>> a) Maybe its an option to put the foreign key to the other model?
>>>>>>> This way you dont need to make a join to find out if there is a 
>>>>>>> relation.
>>>>>>>
>>>>>>> b) Save the existing ralation status to model A
>>>>>>>
>>>>>>> c) cache the A.objects.filter(bs__isnull=False) query
>>>>>>>
>>>>>>> But apart from that i fear you cannot do much more, since this is
>>>>>>> just a DB and not a Django ORM question.
>>>>>>>
>>>>>>>
>>>>>>> Am Freitag, 2. Februar 2018 14:47:45 UTC+1 schrieb Web Architect:
>>>>>>>>
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I am trying to optimise Django queries on my ecommerce website. One
>>>>>>>> of the fundamental query is where I have no clue how to make 
>>>>>>>> efficient. It
>>>>>>>> could be trivial and probably been known long time back. But I am new 
>>>>>>>> to
>>>>>>>> Django and wo

Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-02 Thread Furbee
There are a couple options you could try to see which is the best fit for
your data. With DEBUG=True in settings.py you can check the actual queries
and process time. It depends on the sizes of A and B. Another query you can
run is:

A.objects.exclude(id__in=B.objects.all().values_list('a_id', flat=True))

When I tried, it seemed to be about the same speed with my test data as the
one you had A.objects.filter(bs__isnull=True).

To see what queries are generated and the query time with DEBUG=True:
Open your Django Python Shell
>>> A.objects.exclude(id__in=B.objects.all().values_list('a_id', flat=True))
>>> A.objects.filter(bs__isnull=True)
>>> from django.db import connection
>>> for q in connection.queries:
>>> print("{0}: {1}".format(q['sql'], q['time']))

This will show you both queries generated and how long it took to get a
response from your DB.

You can also write raw SQL, if you can make one more efficiently.

Furbee

On Fri, Feb 2, 2018 at 10:56 AM, Vijay Khemlani  wrote:

> "with large of records in A and B, the above takes lot of time"
>
> How long? At first glance it doesn't look like a complex query or
> something particularly inefficient for a DB.
>
> On Fri, Feb 2, 2018 at 11:31 AM, Andy  wrote:
>
>> not that i know of
>>
>>
>> Am Freitag, 2. Februar 2018 15:28:26 UTC+1 schrieb Web Architect:
>>>
>>> Hi Andy,
>>>
>>> Thanks for your response. I was pondering on option a before posting
>>> this query thinking there could be better ways in django/SQL to handle
>>> this. But now I would probably go with a.
>>>
>>> Thanks.
>>>
>>> On Friday, February 2, 2018 at 7:50:53 PM UTC+5:30, Andy wrote:
>>>>
>>>> a) Maybe its an option to put the foreign key to the other model? This
>>>> way you dont need to make a join to find out if there is a relation.
>>>>
>>>> b) Save the existing ralation status to model A
>>>>
>>>> c) cache the A.objects.filter(bs__isnull=False) query
>>>>
>>>> But apart from that i fear you cannot do much more, since this is just
>>>> a DB and not a Django ORM question.
>>>>
>>>>
>>>> Am Freitag, 2. Februar 2018 14:47:45 UTC+1 schrieb Web Architect:
>>>>>
>>>>> Hi,
>>>>>
>>>>> I am trying to optimise Django queries on my ecommerce website. One of
>>>>> the fundamental query is where I have no clue how to make efficient. It
>>>>> could be trivial and probably been known long time back. But I am new to
>>>>> Django and would appreciate any help. This is primarily for one to many or
>>>>> many to many relations.
>>>>>
>>>>> Following is an example scenario:
>>>>> (Please pardon my syntax as I want to put across the concept and not
>>>>> the exact django code unless it's really needed):
>>>>>
>>>>> Model A:
>>>>>
>>>>> class A(models.Model):
>>>>> # Fields of model A
>>>>>
>>>>> Model B (which is related to A with foreign key):
>>>>>
>>>>> class B(models.Model):
>>>>> a = models.ForeignKey('A', related_name='bs')
>>>>>
>>>>> Now I would like to find out all As for which there is atleast one b.
>>>>> The only way I know is as follows:
>>>>>
>>>>> A.objects.filter(bs__isnull=False)
>>>>>
>>>>> But the above isn't an optimal way as with large of records in A and
>>>>> B, the above takes lot of time. It gets more inefficient if it's a many to
>>>>> many relationship.
>>>>>
>>>>> Could anyone please let me know the most efficient way to use django
>>>>> queryset for the above scenario?
>>>>>
>>>>> 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+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/73ed5ff7-d4db-4057-a812-01c82bf08cf3%40googlegroups.com
&

Re: Can you people explain why the def _str_() method is used below?

2018-01-09 Thread Furbee
Who you call "you people?" Just kidding.

On Tue, Jan 9, 2018 at 11:27 AM,  wrote:

> Thanks alot James and Projec.Your posts were very helpful to me.
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/70139b94-cc0f-4e93-bb97-42009d41a10f%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACMDPqFZh-17%3DULsuixiob%3D7VkWMYFgPnUVjqK0y34T69ZZv3w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to check if user is already in user database?

2015-01-16 Thread Mark Furbee
Also, you can do a try/catch, but I don't really like this method,
personally:

try:
User.objects.get(username=username)
except User.DoesNotExist:
# user didn't exist in database.

On Fri, Jan 16, 2015 at 9:16 AM, Mark Furbee  wrote:

> Yes, that link will cover the basics...
>
> Here's a couple ways to find out if a query returns any records:
>
> User.objects.filter(username=username).exists()  # .exists() returns
> boolean if records are found.
> User.objects.filter(username=username).count() != 0  # .count()
> returns number of records in query.
> User.objects.filter(username=username).first() is not None # .first()
> returns the first record if there are matches, and None if there aren't
>
>
> On Fri, Jan 16, 2015 at 9:11 AM, James Bennett 
> wrote:
>
>> This may be a good time to review Django's documentation on how to
>> perform database queries:
>>
>>
>> https://docs.djangoproject.com/en/1.7/topics/db/queries/#retrieving-a-single-object-with-get
>>
>> --
>> 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+unsubscr...@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/CAL13Cg8MaAhTh%2B%3DoGTJ75jeZVY8-gt_hMkUTjZxyLxFkQ%2Bx36Q%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAL13Cg8MaAhTh%2B%3DoGTJ75jeZVY8-gt_hMkUTjZxyLxFkQ%2Bx36Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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+unsubscr...@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/CACMDPqG8-V--9HB_c2YM%3DYchq7bhOmPTA482jLTFwRLpuFLZTQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to check if user is already in user database?

2015-01-16 Thread Mark Furbee
Yes, that link will cover the basics...

Here's a couple ways to find out if a query returns any records:

User.objects.filter(username=username).exists()  # .exists() returns
boolean if records are found.
User.objects.filter(username=username).count() != 0  # .count() returns
number of records in query.
User.objects.filter(username=username).first() is not None # .first()
returns the first record if there are matches, and None if there aren't


On Fri, Jan 16, 2015 at 9:11 AM, James Bennett 
wrote:

> This may be a good time to review Django's documentation on how to perform
> database queries:
>
>
> https://docs.djangoproject.com/en/1.7/topics/db/queries/#retrieving-a-single-object-with-get
>
> --
> 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+unsubscr...@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/CAL13Cg8MaAhTh%2B%3DoGTJ75jeZVY8-gt_hMkUTjZxyLxFkQ%2Bx36Q%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@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/CACMDPqEAEdsAi6Vos91-Erxg4RxUHvh1bZhdTa-%2B5ykMjT0wXw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: ANN: Django website redesign launched

2014-12-16 Thread Mark Furbee
Looks slick to me! Clearly with mobile and responsive design in mind, but
that's what we have to keep in mind these days.

Great job to all contributors involved in this redesign!

On Tue, Dec 16, 2014 at 4:01 PM, Cal Leeming  wrote:
>
> Personally I really like it.
>
> The footer menu contrast is a little bright with the white/light green,
> however it's worth noting that the color/contrast experience will vary
> depending on what equipment your using. Typically if a site has been
> designed on an Apple Thunderbolt/MBP Retina display, then it will look a
> bit crappy on many PC monitors (even the higher quality ones). I used to
> complain about site designs all the time when I was on a PC, since
> switching to an MBP most of these problems disappeared. The same goes for
> font weight, and indeed font rendering, typically OS X renders fonts much
> cleaner than Windows. (This is on the assumption that you are using a PC).
>
> Three spots (the design agency) look like they are using Macs in their
> office according to their office photos, so this might help explain why.
>
> However there are a few bugs;
>
> * code.djangoproject has some indenting issues on header tags (e.g.
> getting involved), and the shaded underline is weird, you can see this
> white background box around it then some grey fading... very strange.
> http://i.imgur.com/q2ejjq0.png
>
> * code.djangoproject ticket list table is "bleeding" over the right hand
> edge
> http://i.imgur.com/ALm4eX0.png
>
> * code.djangoproject query form is not properly designed, small font with
> oddly placed form elements and incorrect use of spacing;
> http://i.imgur.com/t2POMDL.png
>
> Gotta head to bed so I'll cut this short, hope this helps though.
>
> Cal
>
>
> On Tue, Dec 16, 2014 at 11:22 PM, Russell Keith-Magee <
> russ...@keith-magee.com> wrote:
>>
>>
>> On Wed, Dec 17, 2014 at 6:55 AM, Schmitt, Christian <
>> c.schm...@briefdomain.de> wrote:
>>
>>> Somehow I hate it. The website is the worst website I've seen since a
>>> long time.
>>> The contrast is really aweful.
>>> The issue Tracker got unusable due to the colors that aren't focused on
>>> readability.
>>>
>>> Overall it looks like a mess, just to have a new design.
>>>
>>> Doesn't look like a designer or a graphic guy had his hands on that.
>>> I can't realized why some should replace a good and usable design which
>>> had some practical usage and also a good readability with the "thing" we
>>> have now.
>>>
>>> Sorry but I will stick to the old docs as for now or use the PDF ones
>>> with my custom style (since your colors are aweful, too).
>>>
>>> Django should focus on a clear design which is helpful for readability
>>> and not this stupid mess.
>>>
>>
>> Thanks for the feedback. Sorry you don't like what we've rolled out.
>>
>> I can assure you that we *did* engage a "designer or graphic guy" in this
>> process - several in fact - and they all have significant experience in
>> designing "usable designs" with "practical usage". The blog post announcing
>> the launch has the details.
>>
>> The old design was a classic, but you can't say it didn't have problems -
>> from a technical perspective, it was almost unusable on mobile devices;
>> from a functional perspective, it didn't provide a way for us as a project
>> to highlight community efforts, or draw attention to the DSF or provide
>> calls to action for people who aren't discovering Django for the first time.
>>
>> If you've got specific feedback - something we can actually fix or
>> address, not "I don't like it" - please open a ticket. We've already had
>> some comments raised about contrast, which the team is looking into. If
>> there's something else we should know about, let us know and we can address
>> it.
>>
>> Yours,
>> Russ Magee %-)
>>
>> --
>> 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+unsubscr...@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/CAJxq848JSv9gw4C-RpPDuVJi994%2B%2BFOctqp8LYp%2BhqBVE%3DjSgw%40mail.gmail.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>  --
> 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+unsubscr...@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://gr

Re: (1364, "Field 'id' doesn't have a default value") - mysql issue?

2014-04-09 Thread Mark Furbee
You say you imported the database. Did you use syncdb to set up the tables?
It sounds like your comment_id field in MySQL is not set as an
auto-incrementing primary key field. Do you have access to that MySQL
database to check, and or update that field definition?


On Wed, Apr 9, 2014 at 2:42 PM, Adam Teale  wrote:

> Hi Guys
>
> I have been working on a django app that was going well using an sqlite db.
> I've moved it over to mysql and imported the database
>
> Everything looks good
>
> But when I try to use the django comment system that was working well on
> the sqlite db before I get:
>
> OperationalError at /comments/post/
> (1364, "Field 'id' doesn't have a default value")
> Request Method: POST
> Request URL: http://192.168.1.143/comments/post/
> Django Version: 1.6.2
> Exception Type: OperationalError
> Exception Value:
> (1364, "Field 'id' doesn't have a default value")
> Exception Location: 
> /Users/admin/Dropbox/mstudio/code/mBrain/mbrain/venv/lib/python2.7/site-packages/MySQLdb/connections.py
> in defaulterrorhandler, line 36
> Python Executable:
>
>
> I'm a little lost - do i need to set a default value for
> the django.contrib.comments model?
> And how would i do that if I needed to - this has an Object ID field - i
> don't know how I'd set that up
>
>
> Any ideas? What am i missing?
>
> Many thanks!
>
> Adam
>
> --
> 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+unsubscr...@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/18894c72-24c9-41cd-85a1-4dc09072dfb8%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@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/CACMDPqHbdXorWvLLc%2BDy3eEdvd9Q7gaK6-aCqzuG_X9HvSjz%3DQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: I really about to give up Django

2013-08-23 Thread Mark Furbee
I see. I don't understand how this works: {{
itens.instance.idproduto.codigobarra
}} when this doesn't: {{ itens.instance.idproduto.idmercadoria.referencia }}

Can you post your template code?




On Fri, Aug 23, 2013 at 10:13 AM, Fellipe Henrique wrote:

> form.instance is "Pedido"  model, not "ItensPedido".
>
> My "ItensPedido" has "idproduto" not my "Pedido". and all idproduto has
> idmercadoria, it a required field, never, never go null`s this field.
>
> Cheers,
>
> Em sexta-feira, 23 de agosto de 2013 12h15min15s UTC-3, Mark escreveu:
>>
>> Are you sure the idmercadoria is not None on that idproduto record?
>>
>> {{ form.instance.idproduto.**idmerc**adoria }} Does this display
>> anything?
>> How about {{ form.instance.idproduto }}?
>>
>> If these don't display, verify the records in your database. In Django
>> templates, if something is None or does not exist, it will not raise an
>> exception, it just ignores it and remains blank. Also verify the referencia
>> field is not empty. If the field is 'NOT NULL' then it will be an empty
>> string if it is blank.
>>
>>
>>
>> On Thu, Aug 22, 2013 at 12:58 PM, Fellipe Henrique wrote:
>>
>>> No, nothing displayed..
>>>
>>> Em quinta-feira, 22 de agosto de 2013 13h38min04s UTC-3, Mark escreveu:

 Try dropping the .value from referencia. Like {{
 form.instance.idproduto.**idmerc**adoria.referencia }}. Does this work?


 On Thu, Aug 22, 2013 at 9:35 AM, Fellipe Henrique wrote:

> I tried again.. and work if I have just 1 FK, if I have more then one,
> doesn't work, like this:
>
> I have this models:
> Itens -> produto -> mercadoria
>
> itens:
>   idproduto = FK (produto)
> produto:
>   idmercadoria = FK(mercadoria)
> mercadoria:
>   referencia = Char
>
> I try to get "referencia" field, as you told:
>
> {{ form.instance.idproduto.**idmerc**adoria.referencia.value }}
>
> doesn't work.. what I miss?
>
> Here is my complete models, forms and view: http://pastebin.com/**w2Tm
> **yLzt 
>
>  Cheers,
>
>
> Em quinta-feira, 22 de agosto de 2013 13h24min31s UTC-3, Fellipe
> Henrique escreveu:
>
>> Ok, I read that, but the problem persist.. I try to use as you told,
>> but nothing show... and no errors appears..
>>
>> Sorry about my first line.. I just stop here, simple problem, in more
>> then 1 day, and I don't find any solution, anything on internet to...
>>
>> Cheers
>> Fellipe
>>
>>
>>>  --
> 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...@**googlegroups.**com.
> To post to this group, send email to django...@googlegroups.com.
>
> Visit this group at 
> http://groups.google.com/**group**/django-users
> .
> For more options, visit 
> https://groups.google.com/**grou**ps/opt_out
> .
>

  --
>>> 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...@**googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at 
>>> http://groups.google.com/**group/django-users
>>> .
>>> For more options, visit 
>>> https://groups.google.com/**groups/opt_out
>>> .
>>>
>>
>>  --
> 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+unsubscr...@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.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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+unsubscr...@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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I really about to give up Django

2013-08-23 Thread Mark Furbee
Are you sure the idmercadoria is not None on that idproduto record?

{{ form.instance.idproduto.**idmercadoria }} Does this display anything?
How about {{ form.instance.idproduto }}?

If these don't display, verify the records in your database. In Django
templates, if something is None or does not exist, it will not raise an
exception, it just ignores it and remains blank. Also verify the referencia
field is not empty. If the field is 'NOT NULL' then it will be an empty
string if it is blank.



On Thu, Aug 22, 2013 at 12:58 PM, Fellipe Henrique wrote:

> No, nothing displayed..
>
> Em quinta-feira, 22 de agosto de 2013 13h38min04s UTC-3, Mark escreveu:
>>
>> Try dropping the .value from referencia. Like {{ form.instance.idproduto.
>> **idmercadoria.referencia }}. Does this work?
>>
>>
>> On Thu, Aug 22, 2013 at 9:35 AM, Fellipe Henrique wrote:
>>
>>> I tried again.. and work if I have just 1 FK, if I have more then one,
>>> doesn't work, like this:
>>>
>>> I have this models:
>>> Itens -> produto -> mercadoria
>>>
>>> itens:
>>>   idproduto = FK (produto)
>>> produto:
>>>   idmercadoria = FK(mercadoria)
>>> mercadoria:
>>>   referencia = Char
>>>
>>> I try to get "referencia" field, as you told:
>>>
>>> {{ form.instance.idproduto.**idmercadoria.referencia.value }}
>>>
>>> doesn't work.. what I miss?
>>>
>>> Here is my complete models, forms and view: http://pastebin.com/**
>>> w2TmyLzt 
>>>
>>>  Cheers,
>>>
>>>
>>> Em quinta-feira, 22 de agosto de 2013 13h24min31s UTC-3, Fellipe
>>> Henrique escreveu:
>>>
 Ok, I read that, but the problem persist.. I try to use as you told,
 but nothing show... and no errors appears..

 Sorry about my first line.. I just stop here, simple problem, in more
 then 1 day, and I don't find any solution, anything on internet to...

 Cheers
 Fellipe


>  --
>>> 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...@**googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>>
>>> Visit this group at 
>>> http://groups.google.com/**group/django-users
>>> .
>>> For more options, visit 
>>> https://groups.google.com/**groups/opt_out
>>> .
>>>
>>
>>  --
> 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+unsubscr...@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.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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+unsubscr...@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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I really about to give up Django

2013-08-22 Thread Mark Furbee
Are your "nome" and "idade" fields displaying? If so, {{
form.instance.brinq.descricao }} should display the descricao field of the
brinq object associated with that Filhos instance bound to the form in the
formset.


On Thu, Aug 22, 2013 at 9:24 AM, Fellipe Henrique wrote:

> Ok, I read that, but the problem persist.. I try to use as you told, but
> nothing show... and no errors appears..
>
> Sorry about my first line.. I just stop here, simple problem, in more then
> 1 day, and I don't find any solution, anything on internet to...
>
> Cheers
> Fellipe
>
> Em quinta-feira, 22 de agosto de 2013 12h19min31s UTC-3, Tom Evans
> escreveu:
>
>> On Thu, Aug 22, 2013 at 3:28 PM, Fellipe Henrique 
>> wrote:
>> > Hi guys,
>> >
>> > I really about to give up from Django,
>>
>> So should I bother giving you the advice you asked for, since you are
>> just going to give up on Django?
>>
>> > because? I try to do something simple
>> > and I looking, looking around the internet and don't find anything
>> about
>> > this... try this simple example: http://pastebin.com/epazpBcZ
>> >
>> > I just want to get "descricao" field, from "Brinq" model, using a
>> > inlineformSet.
>> >
>> > I can't do this.. I try:  {{ form.brinq__descricao }} , {{
>> > form.brinq_id__descricao }}, {{ form.brinq.descricao }} and {{
>> > form.brinq_id__descricao }}
>> >
>> > I think it`s simple thing to do.. but I don't found anything to do this
>> in
>> > internet..
>> >
>> > Can any one help me in this simple question?
>> >
>> > Thanks.
>> >
>>
>> First of all, a model form that is bound to an instance of a model has
>> an attribute called 'instance' that represents the instance it is
>> bound to. This is mentioned all over the ModelForms documentation, eg
>> here:
>>
>> https://docs.djangoproject.**com/en/1.5/topics/forms/**
>> modelforms/#overriding-the-**clean-method
>>
>> and here:
>>
>> https://docs.djangoproject.**com/en/1.5/topics/forms/**
>> modelforms/#the-save-method
>>
>> Therefore, if you want to output things related to that instance, you
>> can use it in your template:
>>
>> {{ form.instance.brinq.descricao }}
>>
>>
>> Cheers
>>
>> Tom
>>
>  --
> 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+unsubscr...@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.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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+unsubscr...@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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I really about to give up Django

2013-08-22 Thread Mark Furbee
Try dropping the .value from referencia. Like {{
form.instance.idproduto.idmercadoria.referencia }}. Does this work?


On Thu, Aug 22, 2013 at 9:35 AM, Fellipe Henrique wrote:

> I tried again.. and work if I have just 1 FK, if I have more then one,
> doesn't work, like this:
>
> I have this models:
> Itens -> produto -> mercadoria
>
> itens:
>   idproduto = FK (produto)
> produto:
>   idmercadoria = FK(mercadoria)
> mercadoria:
>   referencia = Char
>
> I try to get "referencia" field, as you told:
>
> {{ form.instance.idproduto.idmercadoria.referencia.value }}
>
> doesn't work.. what I miss?
>
> Here is my complete models, forms and view: http://pastebin.com/w2TmyLzt
>
> Cheers,
>
>
> Em quinta-feira, 22 de agosto de 2013 13h24min31s UTC-3, Fellipe Henrique
> escreveu:
>
>> Ok, I read that, but the problem persist.. I try to use as you told, but
>> nothing show... and no errors appears..
>>
>> Sorry about my first line.. I just stop here, simple problem, in more
>> then 1 day, and I don't find any solution, anything on internet to...
>>
>> Cheers
>> Fellipe
>>
>>
>>>  --
> 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+unsubscr...@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.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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+unsubscr...@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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: 'url' template tag throws and error after upgrading to 1.4

2013-04-04 Thread Mark Furbee
Can you run manage.py shell and connect to 'views?'


On Thu, Apr 4, 2013 at 4:13 PM, Mark Furbee  wrote:

> It would appear to me that your missing the path to django in your
> environment. When you upgraded did you also upgrade to another version of
> Python, perhaps? Is the dist-packages/site-packages django folder in the
> same place it was?
>
>
> On Thu, Apr 4, 2013 at 3:58 PM, Bastian wrote:
>
>> I have tried with runserver and debug = True and it gives me the error
>> but when I turn off debug then the site loads fine.
>> Then I installed gunicorn and with debug = true and the error appears but
>> with debug = False the site loads fine but without the static content.
>> I don't know if this is a clue about something wrong in the static
>> settings or if it's just a setting in gunicorn.
>>
>> Any idea?
>>
>> --
>> 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+unsubscr...@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?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>

-- 
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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: 'url' template tag throws and error after upgrading to 1.4

2013-04-04 Thread Mark Furbee
It would appear to me that your missing the path to django in your
environment. When you upgraded did you also upgrade to another version of
Python, perhaps? Is the dist-packages/site-packages django folder in the
same place it was?


On Thu, Apr 4, 2013 at 3:58 PM, Bastian  wrote:

> I have tried with runserver and debug = True and it gives me the error but
> when I turn off debug then the site loads fine.
> Then I installed gunicorn and with debug = true and the error appears but
> with debug = False the site loads fine but without the static content.
> I don't know if this is a clue about something wrong in the static
> settings or if it's just a setting in gunicorn.
>
> Any idea?
>
> --
> 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+unsubscr...@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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: ANNOUNCE: Django 1.5 released

2013-02-26 Thread Mark Furbee
Woo-hoo! Awesome news. We really appreciate all the hard work you guys have
been doing getting this version out.

Thanks a million!

Mark


On Tue, Feb 26, 2013 at 11:44 AM, James Bennett wrote:

> Yup, it's finally here!
>
> * Announcement blog post here:
> https://www.djangoproject.com/weblog/2013/feb/26/15/
> * Release notes here: https://docs.djangoproject.com/en/1.5/releases/1.5/
> * Download it here: https://www.djangoproject.com/download/
>
> --
> 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+unsubscr...@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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Saving browser output as pdf

2013-02-24 Thread Mark Furbee
Django docs (pretty turse):
https://docs.djangoproject.com/en/dev/howto/outputting-pdf/

>From ReportLab site:
http://www.reportlab.com/software/documentation/

Here's a decent quick tutorial:
http://www.blog.pythonlibrary.org/2010/03/08/a-simple-step-by-step-reportlab-tutorial/

Note that what you are proposing is to create an HTML version of the report
and a separate PDF version using ReportLab. Otherwise, if you want to make
what would be an HTML report download as a PDF document, use @Mike's
solution.

Good Luck,

Mark


On Sun, Feb 24, 2013 at 8:04 AM, Satinderpal Singh <
satinder.goray...@gmail.com> wrote:

> On Sun, Feb 24, 2013 at 8:00 PM, Nick Apostolakis 
> wrote:
> > On 24/02/2013 03:15 μμ, Satinderpal Singh wrote:
> >>
> >> Thanks a lot to all. I noted your suggestions, and will try to
> >> implement one which would be best suit to my requirement.
> >>
> >> By the way, i am trying to take pdf output from the models and for
> >> that i required these libraries. Currently, i am using pisa for saving
> >> the output of the report as pdf file.
> >>
> >> Basically i need both outputs, html and pdf, for my clients. I need to
> >>   produce more than 40 different reports as html and pdf so that my
> >> client can take whatever he needed. And if i tried to produce both
> >> html and pdf from views, then it requires functions double to the
> >> reports, two for each html and pdf. So, i need solution which can
> >> convert my html output to the pdf from browser.
> >>
> >>
> >>
> >
> > Hi there, I use the report lab library in my application to produce pdf
> > reports.
> >
> > The user sees the report in html of course and has an option to download
> it
> > as csv or as pdf.
> > The pdf part is accomplished with reportlab library.
> >
> That exactly i want, please tell me how will i do this.
>
>
> > Cheers
> >
> > --
> >  --
> >Nick Apostolakis
> >   e-mail: nicka...@oncrete.gr
> >  Web Site: http://nick.oncrete.gr
> >  --
> >
> >
> >
> > --
> > 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+unsubscr...@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?hl=en.
> > For more options, visit https://groups.google.com/groups/opt_out.
> >
> >
>
>
>
> --
> Satinderpal Singh
> http://satindergoraya.blogspot.in/
> http://satindergoraya91.blogspot.in/
>
> --
> 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+unsubscr...@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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Saving browser output as pdf

2013-02-24 Thread Mark Furbee
Mike DeWitt's answer is most appropriate. In you view define an argument
'pdf=False' and when returning the response from uou view, if pdf is False,
return regular HttpResponse. If pdf is True, follw @Mike's reply to set
response Content type to PDF. It is really easy to return what would be an
html response as a pdf download. You could even show report as html, with
link to download as PDF. The PDF link would go to the same view method with
'pdf=True'.
On Feb 24, 2013 6:30 AM, "Nick Apostolakis"  wrote:

> On 24/02/2013 03:15 μμ, Satinderpal Singh wrote:
>
>> Thanks a lot to all. I noted your suggestions, and will try to
>> implement one which would be best suit to my requirement.
>>
>> By the way, i am trying to take pdf output from the models and for
>> that i required these libraries. Currently, i am using pisa for saving
>> the output of the report as pdf file.
>>
>> Basically i need both outputs, html and pdf, for my clients. I need to
>>   produce more than 40 different reports as html and pdf so that my
>> client can take whatever he needed. And if i tried to produce both
>> html and pdf from views, then it requires functions double to the
>> reports, two for each html and pdf. So, i need solution which can
>> convert my html output to the pdf from browser.
>>
>>
>>
>>
> Hi there, I use the report lab library in my application to produce pdf
> reports.
>
> The user sees the report in html of course and has an option to download
> it as csv or as pdf.
> The pdf part is accomplished with reportlab library.
>
> Cheers
>
> --
>  --**--**--
>Nick Apostolakis
>   e-mail: nicka...@oncrete.gr
>  Web Site: http://nick.oncrete.gr
>  --**--**--
>
>
> --
> 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?hl=en
> .
> For more options, visit 
> https://groups.google.com/**groups/opt_out
> .
>
>
>

-- 
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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: can someone rewrite this line please

2013-02-21 Thread Mark Furbee
No worries, Mike. Any time!


On Thu, Feb 21, 2013 at 3:17 AM, MikeKJ  wrote:

> Thank you Mark spot on!
>
> Really appreciate it
>
>
>
>
>
> On Wednesday, February 20, 2013 3:58:28 PM UTC, Mark wrote:
>
>> Not sure if you need the json.large to be compiled or if that should be
>> part of the string. The biggest issue was you had a single-quote before
>> onmouseover. After that, you have to escape the single-quote before > src and either escape the + json.large + or leave it so that Type will
>> compile it. Give this a try, I think it is what you want:
>>
>> large = '> src="'+json.large+'"/>\',LEFT, true, OFFSETY, -250, OFFSETX, 0, WIDTH,
>> 800)\" target=\"_blank\">';
>>
>> FYI: if you use an IDE like Eclipse, it will show you what is and isn't
>> escaped to some degree, using colored text to denote quoted strings versus
>> compiled commands.
>>
>> Cheers,
>>
>> Mark
>>
>> On Wed, Feb 20, 2013 at 6:25 AM, MikeKJ  wrote:
>>
>>> large = '>> src='+json.large+'/>',LEFT, true, OFFSETY, -250, OFFSETX, 0, WIDTH, 800)\"
>>> target=\"_blank\">';
>>>
>>> so that is comes out of the jquery call as proper html, it needs more
>>> escaping somewhere but damned if I can see it.
>>>
>>>  --
>>> 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...@**googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>>
>>> Visit this group at 
>>> http://groups.google.com/**group/django-users?hl=en
>>> .
>>> For more options, visit 
>>> https://groups.google.com/**groups/opt_out
>>> .
>>>
>>>
>>>
>>
>>  --
> 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+unsubscr...@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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: can someone rewrite this line please

2013-02-20 Thread Mark Furbee
Not sure if you need the json.large to be compiled or if that should be
part of the string. The biggest issue was you had a single-quote before
onmouseover. After that, you have to escape the single-quote before \',LEFT, true, OFFSETY, -250, OFFSETX, 0, WIDTH,
800)\" target=\"_blank\">';

FYI: if you use an IDE like Eclipse, it will show you what is and isn't
escaped to some degree, using colored text to denote quoted strings versus
compiled commands.

Cheers,

Mark

On Wed, Feb 20, 2013 at 6:25 AM, MikeKJ  wrote:

> large = ' src='+json.large+'/>',LEFT, true, OFFSETY, -250, OFFSETX, 0, WIDTH, 800)\"
> target=\"_blank\">';
>
> so that is comes out of the jquery call as proper html, it needs more
> escaping somewhere but damned if I can see it.
>
> --
> 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+unsubscr...@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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: DJANGO_DEFAULT_SETTINGS

2012-08-14 Thread Furbee
DJANGO_SETTINGS_MODULE is an environment variable that must be set. I
believe this is taken care of for you when you create a project using
django-admin. You may need to create it manually. Without that
environmental variable set, the Django shell won't open. As Jirka said,
please review the tutorials and documentation, especially Tutorial 1-4.
This will get you on your way to installing and using Django via the web,
and shell.

Furbee

On Tue, Aug 14, 2012 at 2:50 PM, Jirka Vejrazka wrote:

> > right, I was being very brief in my description!
> > But it is the following:
> > I want to insert data into the database from the shell, django shell, but
> > the result is always that you can not import the settings because the va
> > riavel DJANGO_SETTINGS_MODULE is not set
>
> Did you read my previous email and checked the documentation at all?
> It's all described there:
>
> https://docs.djangoproject.com/en/1.4/faq/usage/
> https://docs.djangoproject.com/en/1.4/ref/django-admin/
>
> If you read this and *still* have a problem, come back and ask a
> specific question with what you already tried (e.g. do you have a
> database defined and created?) and what specific error(s) are you
> experiencing.
>
>   HTH
>
>  Jirka
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Database Error at /admin/coltrane/entry/add/

2012-05-16 Thread Furbee
Great to hear it. When you move to a production server where you will not
be able to delete tables, you will want to use South, since syncdb does not
implement changes (additions/deletions) to fields. Django's syncdb script
will not touch an existing table, because they do not want to delete data.
However, South will implement changes to table structure, and it is
actually incredibly easy to set up!

Happy Coding,

Furbee

On Wed, May 16, 2012 at 1:21 AM, Gethin Llyn ab Alwyn wrote:

> Thank you for your answer, deleting the table and running manage.py syncdb
> did the trick
>
> Geth
>
> On 15 May 2012 17:02, Furbee  wrote:
>
>> Have you checked your database to see that the field actually exists. If
>> you've added excerpt_html since you ran python manage.py syncdb you won't
>> have the field in the table. You would either need to use South to include
>> it, add it by hand to the table, or delete the table and run python
>> manage.py syncdb to have it recreated including this field.
>>
>> Furbee
>>
>> On Tue, May 15, 2012 at 8:57 AM, Gethin Llyn ab Alwyn 
>> wrote:
>>
>>> Hello all!
>>>
>>> I'm following James Bennett's book Practical Django Projects, and I've
>>> got stuck at page 65 Chapter 4. On that page, there is an instruction to
>>> add an entry through the models created and added to admin interface under
>>> "Entries". I can populate the fields through the add link, but when it
>>> comes to saving an entry, this is the error I get:
>>> http://dpaste.com/hold/748531/
>>>
>>> This is the traceback of that error: http://dpaste.com/hold/748536/
>>>
>>> These are the admin.py http://dpaste.com/hold/748537/
>>>  models.py http://dpaste.com/hold/748538/
>>>   and settings.py  http://dpaste.com/hold/748529/
>>>
>>> I'm wondering where I went wrong, I've googled the error but I can't
>>> find anything specific. I'm sorry if it's a dumb question!
>>>
>>> Thanks
>>>
>>> Geth
>>>
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Database Error at /admin/coltrane/entry/add/

2012-05-15 Thread Furbee
Have you checked your database to see that the field actually exists. If
you've added excerpt_html since you ran python manage.py syncdb you won't
have the field in the table. You would either need to use South to include
it, add it by hand to the table, or delete the table and run python
manage.py syncdb to have it recreated including this field.

Furbee

On Tue, May 15, 2012 at 8:57 AM, Gethin Llyn ab Alwyn wrote:

> Hello all!
>
> I'm following James Bennett's book Practical Django Projects, and I've got
> stuck at page 65 Chapter 4. On that page, there is an instruction to add an
> entry through the models created and added to admin interface under
> "Entries". I can populate the fields through the add link, but when it
> comes to saving an entry, this is the error I get:
> http://dpaste.com/hold/748531/
>
> This is the traceback of that error: http://dpaste.com/hold/748536/
>
> These are the admin.py http://dpaste.com/hold/748537/
>  models.py http://dpaste.com/hold/748538/
>   and settings.py  http://dpaste.com/hold/748529/
>
> I'm wondering where I went wrong, I've googled the error but I can't find
> anything specific. I'm sorry if it's a dumb question!
>
> Thanks
>
> Geth
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Middleware order

2012-05-15 Thread Furbee
I don't know, but the revision middleware smells like it could be the
culprit. It is the last module in processing the request, and the first one
processing the response back up the chain. Maybe it is returning the old
data. Just a stab in the dark.

Furbee

On Tue, May 15, 2012 at 8:23 AM, David  wrote:

> Hi
>
> This is how my middleware is currently ordered:
>
> 'django.middleware.cache.UpdateCacheMiddleware',
> 'django.middleware.gzip.GZipMiddleware',
> 'django.contrib.sessions.middleware.SessionMiddleware',
> 'django.middleware.common.CommonMiddleware',
> 'django.middleware.csrf.CsrfViewMiddleware',
> 'django.contrib.auth.middleware.AuthenticationMiddleware',
> 'django.contrib.messages.middleware.MessageMiddleware',
> 'django.middleware.transaction.TransactionMiddleware',
> 'django.middleware.clickjacking.XFrameOptionsMiddleware',
> 'django.middleware.cache.FetchFromCacheMiddleware',
> 'debug_toolbar.middleware.DebugToolbarMiddleware',
> 'reversion.middleware.RevisionMiddleware',
>
> My problem for example is this. I have a form editting an object. If I
> submit/save the object it is saved successfully, however when redirecting
> back to that edit object form the old data persists. I suspect this is down
> to the order of my middleware.
>
> Have I gone wrong somewhere?
>
> Thank you
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/jkFCQ_SsvtoJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Dajaxice is not defined!!! please heelpppp!! :(

2012-05-04 Thread Furbee
If you are getting this error it is because your view is not returning an
HttpResponse object. You need to wrap your return in an HttpResponse, or
use the shortcut render_to_response() like:

return render_to_response('template.htm', {'data':
'to_supply_to_template'}, context_instance=RequestContext(request))

or:

return HttpResponse(my_json_object)

This may not solve your problem and get dajax working, but it may be a step
in the right direction. I personally battled with some of the confining
aspects of Dajax and ultimately went back to using jQuery straight up. This
allowed me to write some client side trapping/displaying of errors. In my
views I try the code and catch exceptions, then report to admins and return
the error. My return callback javascript function is universal, it checks
the JSON object returned for the err field which is 0 or 1. If it is 1, the
error (stored in JSON['return_error']) is alerted to the user. If there was
no error, it goes through with the callback that was intended (which was
also stored in JSON['callback']). For me, this preserves the error
reporting to admins and allows the user to see that there was an exception,
instead of them thinking everything went through fine since it is input
from their perspective correctly.

Cheers,

Furbee

On Fri, May 4, 2012 at 8:48 AM, Tom Evans  wrote:

> On Fri, May 4, 2012 at 4:06 PM, doniyor 
> wrote:
> > if i call the dajaxice.core.js directly from address bar, it shows an
> error
> > saying: ValueError at /dajaxice/dajaxice.core.js The view
> home.views.index
> > didn't return an HttpResponse object.
> >
> > so it means, i am serving dajaxice.core.js in a wrong way, right?
> >
>
> You may get better results asking about Dajax on the Dajax mailing list:
>
> http://groups.google.com/group/dajaxproject
>
> Cheers
>
> Tom
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: where did I install Django

2012-03-20 Thread Furbee
>From an answer on stackoverflow.com (
http://stackoverflow.com/questions/122327/how-do-i-find-the-location-of-my-python-site-packages-directory
):

Enter python shell by executing python binary:

from distutils.sysconfig import get_python_lib
print(get_python_lib())


It usually resides in a folder named site-packages or dist-packages
somewhere in the Python directory. In Windows it is different than in Unix.

When all else fails, you can run a find command on Unix, or a do an
advanced search in Windows.

On Tue, Mar 20, 2012 at 3:30 PM, jdw  wrote:

> Newbie alert...
>
> I installed Django and finished the first tutorial.  On the second one, I
> could not log in to the website because  I didn't set a superuser.
> Ultimately, I figured out my problem, but I realized I have no idea where I
> installed Django.  Is there an easy way to find out where the code lives?
>
> I realized I had no idea when the tutorial suggested running this:
>
> python /path/to/django/contrib/auth/create_superuser.py
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/9FZCBitFicMJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Getting URL from within a template

2012-03-14 Thread Furbee
Gotcha, you are filtering the QuerySet in Django, returning to client, and
further filtering with jQuery. Makes sense now. :-)

Happy Coding!

Furbee

On Wed, Mar 14, 2012 at 2:11 PM, Larry Martell wrote:

> On Tue, Mar 13, 2012 at 4:26 PM, Furbee  wrote:
> > Oh, you are filtering in the template, using Django, sorry. I thought you
> > meant you pass it to the template and use jQuery to filter. My bad. :-)
>
> I am filtering in the template using jQuery.
>
> >
> > Cheers
> >
> >
> > On Tue, Mar 13, 2012 at 3:25 PM, Furbee  wrote:
> >>
> >> Aha! Very nice. As a sidebar, you said you pass the filter string back
> to
> >> the template so it can apply filtering on the new data set. This makes
> me
> >> think that filtering is being done on the entire data set from the
> browser,
> >> instead of the server. Maybe I misunderstood, but if so, I would suggest
> >> filtering the data on Django's end and simply returning the filtered
> >> QuerySet. This may make the page load faster and would be scalable for
> >> larger lists where lots of records are being filtered by the client
> browser.
> >>
> >>
> >> On Tue, Mar 13, 2012 at 3:01 PM, Larry Martell  >
> >> wrote:
> >>>
> >>> On Tue, Mar 13, 2012 at 3:53 PM, Furbee  wrote:
> >>> > Gotcha, I was unclear. You can have jQuery modify the URL without
> >>> > actually
> >>> > requesting the page from the webserver, I thought that was what you
> >>> > meant.
> >>> > This comes in handy when you want to use javascript to update the URL
> >>> > without requesting a new page from the server in case the user hits
> F5
> >>> > or
> >>> > refreshes the page, it will request the updated URL instead of the
> >>> > original.
> >>> >
> >>> > So, you can do this as you mentioned, or you can parse the
> request.GET
> >>> > dictionary and return them as variables to the template from the
> view.
> >>>
> >>> There's a 'live filtering' function on the page. It's text field with
> >>> a keyup event handler. Each time the field gets updated the data
> >>> currently on the screen is filtered, and the URL is updated to include
> >>> the current filter string so that when the user pages forward or
> >>> backwards through the data (which is a return back to the server), the
> >>> filter string can get passed back into the template so it can apply
> >>> the filtering on the new data set
> >>>
> >>>
> >>> > On Tue, Mar 13, 2012 at 2:42 PM, Larry Martell
> >>> > 
> >>> > wrote:
> >>> >>
> >>> >> On Tue, Mar 13, 2012 at 3:33 PM, Furbee 
> wrote:
> >>> >> > Good deal, but if you send the page to the client, then jQuery
> >>> >> > updates
> >>> >> > the
> >>> >> > URL, the {{ request.get_full_path }} is still only able to have
> the
> >>> >> > original
> >>> >> > URL that was requested. Once the page is sent to the client,
> >>> >> > Django/Python
> >>> >> > is done and cannot manipulate the page, unless you are using AJAX
> to
> >>> >> > get
> >>> >> > updated details.
> >>> >>
> >>> >> When the URL that gets updated by jQuery is clicked on, it goes back
> >>> >> to Django/Python and the {{ request.get_full_path }} gets updated.
> >>> >>
> >>> >>
> >>> >> > On Tue, Mar 13, 2012 at 2:23 PM, Larry Martell
> >>> >> > 
> >>> >> > wrote:
> >>> >> >>
> >>> >> >> On Tue, Mar 13, 2012 at 2:19 PM, Furbee 
> >>> >> >> wrote:
> >>> >> >> > Hi Larry,
> >>> >> >> >
> >>> >> >> > render_to_response is one of many ways to return an
> HttpResponse
> >>> >> >> > to
> >>> >> >> > send
> >>> >> >> > to
> >>> >> >> > the client. Wherever your view does the return, you can pass
> >>> >> >> > these
> >>> >> >> > GET
> >>> >> >> > variables.
> >>> >> >> >
> >>> &g

Re: Getting URL from within a template

2012-03-13 Thread Furbee
Oh, you are filtering in the template, using Django, sorry. I thought you
meant you pass it to the template and use jQuery to filter. My bad. :-)

Cheers

On Tue, Mar 13, 2012 at 3:25 PM, Furbee  wrote:

> Aha! Very nice. As a sidebar, you said you pass the filter string back to
> the template so it can apply filtering on the new data set. This makes me
> think that filtering is being done on the entire data set from the browser,
> instead of the server. Maybe I misunderstood, but if so, I would suggest
> filtering the data on Django's end and simply returning the filtered
> QuerySet. This may make the page load faster and would be scalable for
> larger lists where lots of records are being filtered by the client browser.
>
>
> On Tue, Mar 13, 2012 at 3:01 PM, Larry Martell wrote:
>
>> On Tue, Mar 13, 2012 at 3:53 PM, Furbee  wrote:
>> > Gotcha, I was unclear. You can have jQuery modify the URL without
>> actually
>> > requesting the page from the webserver, I thought that was what you
>> meant.
>> > This comes in handy when you want to use javascript to update the URL
>> > without requesting a new page from the server in case the user hits F5
>> or
>> > refreshes the page, it will request the updated URL instead of the
>> original.
>> >
>> > So, you can do this as you mentioned, or you can parse the request.GET
>> > dictionary and return them as variables to the template from the view.
>>
>> There's a 'live filtering' function on the page. It's text field with
>> a keyup event handler. Each time the field gets updated the data
>> currently on the screen is filtered, and the URL is updated to include
>> the current filter string so that when the user pages forward or
>> backwards through the data (which is a return back to the server), the
>> filter string can get passed back into the template so it can apply
>> the filtering on the new data set
>>
>>
>> > On Tue, Mar 13, 2012 at 2:42 PM, Larry Martell > >
>> > wrote:
>> >>
>> >> On Tue, Mar 13, 2012 at 3:33 PM, Furbee  wrote:
>> >> > Good deal, but if you send the page to the client, then jQuery
>> updates
>> >> > the
>> >> > URL, the {{ request.get_full_path }} is still only able to have the
>> >> > original
>> >> > URL that was requested. Once the page is sent to the client,
>> >> > Django/Python
>> >> > is done and cannot manipulate the page, unless you are using AJAX to
>> get
>> >> > updated details.
>> >>
>> >> When the URL that gets updated by jQuery is clicked on, it goes back
>> >> to Django/Python and the {{ request.get_full_path }} gets updated.
>> >>
>> >>
>> >> > On Tue, Mar 13, 2012 at 2:23 PM, Larry Martell <
>> larry.mart...@gmail.com>
>> >> > wrote:
>> >> >>
>> >> >> On Tue, Mar 13, 2012 at 2:19 PM, Furbee 
>> wrote:
>> >> >> > Hi Larry,
>> >> >> >
>> >> >> > render_to_response is one of many ways to return an HttpResponse
>> to
>> >> >> > send
>> >> >> > to
>> >> >> > the client. Wherever your view does the return, you can pass these
>> >> >> > GET
>> >> >> > variables.
>> >> >> >
>> >> >> > However, if they are being generated by jQuery, dynamically, you
>> >> >> > should
>> >> >> > be
>> >> >> > using jQuery/javascript to read them and deal with them. This
>> should
>> >> >> > be
>> >> >> > client side javascript code. To read the current URL string in
>> >> >> > jQuery, I
>> >> >> > found a nice little article
>> >> >> >
>> >> >> >
>> >> >> > at
>> http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html
>>  which
>> >> >> > should demonstrate how to get these in javascript on the
>> client-side
>> >> >> > browser.
>> >> >>
>> >> >> I was able to get the entire URL with {{ request.get_full_path }}
>> >> >>
>> >> >> But thanks for the link - looks like it could be very useful in the
>> >> >> future.
>> >> >>
>> >> >>
>> >> >> > On Tue, Mar 13, 20

Re: Getting URL from within a template

2012-03-13 Thread Furbee
Aha! Very nice. As a sidebar, you said you pass the filter string back to
the template so it can apply filtering on the new data set. This makes me
think that filtering is being done on the entire data set from the browser,
instead of the server. Maybe I misunderstood, but if so, I would suggest
filtering the data on Django's end and simply returning the filtered
QuerySet. This may make the page load faster and would be scalable for
larger lists where lots of records are being filtered by the client browser.

On Tue, Mar 13, 2012 at 3:01 PM, Larry Martell wrote:

> On Tue, Mar 13, 2012 at 3:53 PM, Furbee  wrote:
> > Gotcha, I was unclear. You can have jQuery modify the URL without
> actually
> > requesting the page from the webserver, I thought that was what you
> meant.
> > This comes in handy when you want to use javascript to update the URL
> > without requesting a new page from the server in case the user hits F5 or
> > refreshes the page, it will request the updated URL instead of the
> original.
> >
> > So, you can do this as you mentioned, or you can parse the request.GET
> > dictionary and return them as variables to the template from the view.
>
> There's a 'live filtering' function on the page. It's text field with
> a keyup event handler. Each time the field gets updated the data
> currently on the screen is filtered, and the URL is updated to include
> the current filter string so that when the user pages forward or
> backwards through the data (which is a return back to the server), the
> filter string can get passed back into the template so it can apply
> the filtering on the new data set
>
>
> > On Tue, Mar 13, 2012 at 2:42 PM, Larry Martell 
> > wrote:
> >>
> >> On Tue, Mar 13, 2012 at 3:33 PM, Furbee  wrote:
> >> > Good deal, but if you send the page to the client, then jQuery updates
> >> > the
> >> > URL, the {{ request.get_full_path }} is still only able to have the
> >> > original
> >> > URL that was requested. Once the page is sent to the client,
> >> > Django/Python
> >> > is done and cannot manipulate the page, unless you are using AJAX to
> get
> >> > updated details.
> >>
> >> When the URL that gets updated by jQuery is clicked on, it goes back
> >> to Django/Python and the {{ request.get_full_path }} gets updated.
> >>
> >>
> >> > On Tue, Mar 13, 2012 at 2:23 PM, Larry Martell <
> larry.mart...@gmail.com>
> >> > wrote:
> >> >>
> >> >> On Tue, Mar 13, 2012 at 2:19 PM, Furbee 
> wrote:
> >> >> > Hi Larry,
> >> >> >
> >> >> > render_to_response is one of many ways to return an HttpResponse to
> >> >> > send
> >> >> > to
> >> >> > the client. Wherever your view does the return, you can pass these
> >> >> > GET
> >> >> > variables.
> >> >> >
> >> >> > However, if they are being generated by jQuery, dynamically, you
> >> >> > should
> >> >> > be
> >> >> > using jQuery/javascript to read them and deal with them. This
> should
> >> >> > be
> >> >> > client side javascript code. To read the current URL string in
> >> >> > jQuery, I
> >> >> > found a nice little article
> >> >> >
> >> >> >
> >> >> > at
> http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html
>  which
> >> >> > should demonstrate how to get these in javascript on the
> client-side
> >> >> > browser.
> >> >>
> >> >> I was able to get the entire URL with {{ request.get_full_path }}
> >> >>
> >> >> But thanks for the link - looks like it could be very useful in the
> >> >> future.
> >> >>
> >> >>
> >> >> > On Tue, Mar 13, 2012 at 11:57 AM, Larry Martell
> >> >> > 
> >> >> > wrote:
> >> >> >>
> >> >> >> On Tue, Mar 13, 2012 at 12:38 PM, Furbee 
> >> >> >> wrote:
> >> >> >> > I think you want to actually get these in the view code and pass
> >> >> >> > them
> >> >> >> > to
> >> >> >> > the
> >> >> >> > template as named variables. For example:
> >> >> >> >
> >> >> &

Re: Getting URL from within a template

2012-03-13 Thread Furbee
Gotcha, I was unclear. You can have jQuery modify the URL without actually
requesting the page from the webserver, I thought that was what you meant.
This comes in handy when you want to use javascript to update the URL
without requesting a new page from the server in case the user hits F5 or
refreshes the page, it will request the updated URL instead of the original.

So, you can do this as you mentioned, or you can parse the request.GET
dictionary and return them as variables to the template from the view.

Cheers

On Tue, Mar 13, 2012 at 2:42 PM, Larry Martell wrote:

> On Tue, Mar 13, 2012 at 3:33 PM, Furbee  wrote:
> > Good deal, but if you send the page to the client, then jQuery updates
> the
> > URL, the {{ request.get_full_path }} is still only able to have the
> original
> > URL that was requested. Once the page is sent to the client,
> Django/Python
> > is done and cannot manipulate the page, unless you are using AJAX to get
> > updated details.
>
> When the URL that gets updated by jQuery is clicked on, it goes back
> to Django/Python and the {{ request.get_full_path }} gets updated.
>
>
> > On Tue, Mar 13, 2012 at 2:23 PM, Larry Martell 
> > wrote:
> >>
> >> On Tue, Mar 13, 2012 at 2:19 PM, Furbee  wrote:
> >> > Hi Larry,
> >> >
> >> > render_to_response is one of many ways to return an HttpResponse to
> send
> >> > to
> >> > the client. Wherever your view does the return, you can pass these GET
> >> > variables.
> >> >
> >> > However, if they are being generated by jQuery, dynamically, you
> should
> >> > be
> >> > using jQuery/javascript to read them and deal with them. This should
> be
> >> > client side javascript code. To read the current URL string in
> jQuery, I
> >> > found a nice little article
> >> >
> >> > at
> http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html
>  which
> >> > should demonstrate how to get these in javascript on the client-side
> >> > browser.
> >>
> >> I was able to get the entire URL with {{ request.get_full_path }}
> >>
> >> But thanks for the link - looks like it could be very useful in the
> >> future.
> >>
> >>
> >> > On Tue, Mar 13, 2012 at 11:57 AM, Larry Martell
> >> > 
> >> > wrote:
> >> >>
> >> >> On Tue, Mar 13, 2012 at 12:38 PM, Furbee 
> wrote:
> >> >> > I think you want to actually get these in the view code and pass
> them
> >> >> > to
> >> >> > the
> >> >> > template as named variables. For example:
> >> >> >
> >> >> > return render_to_response('page.htm',
> >> >> > {'date_time': request.GET['date_time'], 'submit_preview':
> >> >> > request.GET['submit_preview'], 'event_type':
> >> >> > request.GET['event_type'],
> >> >> > 'filterValue':
> >> >> >
> >> >> >
> request.GET['_filterValue']}, context_instance=RequestContext(request))
> >> >> >
> >> >> > From the template, now, the different variables are available. {{
> >> >> > date_time
> >> >> > }}, {{ submit_preview }}, {{ event_type }}, {{ filterValue }}.
> That's
> >> >> > how I
> >> >> > would handle it at least.
> >> >>
> >> >> The URL gets created dynamically by jQuery code in a template. Not
> all
> >> >> these fields are always present. Also, render_to_response is not
> used.
> >> >> (I'm
> >> >> fairly new to both django and this job, and I just grepped through
> the
> >> >> entire code base and it wasn't found.)
> >> >>
> >> >>
> >> >> >
> >> >> > Furbee
> >> >> >
> >> >> > On Tue, Mar 13, 2012 at 11:27 AM, Larry Martell
> >> >> > 
> >> >> > wrote:
> >> >> >>
> >> >> >> On Tue, Mar 13, 2012 at 11:58 AM, Xavier Ordoquy
> >> >> >> 
> >> >> >> wrote:
> >> >> >> >
> >> >> >> > Le 13 mars 2012 à 18:40, Larry Martell a écrit :
> >> >> >> >
> >> >> >> >> On Tue, Mar 13, 2012 at 11:26 AM, Xav

Re: Getting URL from within a template

2012-03-13 Thread Furbee
Good deal, but if you send the page to the client, then jQuery updates the
URL, the {{ request.get_full_path }} is still only able to have the
original URL that was requested. Once the page is sent to the client,
Django/Python is done and cannot manipulate the page, unless you are using
AJAX to get updated details.

Cheers

On Tue, Mar 13, 2012 at 2:23 PM, Larry Martell wrote:

> On Tue, Mar 13, 2012 at 2:19 PM, Furbee  wrote:
> > Hi Larry,
> >
> > render_to_response is one of many ways to return an HttpResponse to send
> to
> > the client. Wherever your view does the return, you can pass these GET
> > variables.
> >
> > However, if they are being generated by jQuery, dynamically, you should
> be
> > using jQuery/javascript to read them and deal with them. This should be
> > client side javascript code. To read the current URL string in jQuery, I
> > found a nice little article
> > at
> http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html
>  which
> > should demonstrate how to get these in javascript on the client-side
> > browser.
>
> I was able to get the entire URL with {{ request.get_full_path }}
>
> But thanks for the link - looks like it could be very useful in the future.
>
>
> > On Tue, Mar 13, 2012 at 11:57 AM, Larry Martell  >
> > wrote:
> >>
> >> On Tue, Mar 13, 2012 at 12:38 PM, Furbee  wrote:
> >> > I think you want to actually get these in the view code and pass them
> to
> >> > the
> >> > template as named variables. For example:
> >> >
> >> > return render_to_response('page.htm',
> >> > {'date_time': request.GET['date_time'], 'submit_preview':
> >> > request.GET['submit_preview'], 'event_type':
> request.GET['event_type'],
> >> > 'filterValue':
> >> >
> request.GET['_filterValue']}, context_instance=RequestContext(request))
> >> >
> >> > From the template, now, the different variables are available. {{
> >> > date_time
> >> > }}, {{ submit_preview }}, {{ event_type }}, {{ filterValue }}. That's
> >> > how I
> >> > would handle it at least.
> >>
> >> The URL gets created dynamically by jQuery code in a template. Not all
> >> these fields are always present. Also, render_to_response is not used.
> (I'm
> >> fairly new to both django and this job, and I just grepped through the
> >> entire code base and it wasn't found.)
> >>
> >>
> >> >
> >> > Furbee
> >> >
> >> > On Tue, Mar 13, 2012 at 11:27 AM, Larry Martell
> >> > 
> >> > wrote:
> >> >>
> >> >> On Tue, Mar 13, 2012 at 11:58 AM, Xavier Ordoquy <
> xordo...@linovia.com>
> >> >> wrote:
> >> >> >
> >> >> > Le 13 mars 2012 à 18:40, Larry Martell a écrit :
> >> >> >
> >> >> >> On Tue, Mar 13, 2012 at 11:26 AM, Xavier Ordoquy
> >> >> >> 
> >> >> >> wrote:
> >> >> >>> Hi
> >> >> >>>
> >> >> >>> Le 13 mars 2012 à 18:11, larry.mart...@gmail.com a écrit :
> >> >> >>>
> >> >> >>>> From within a template can I find out the URL that caused the
> >> >> >>>> template
> >> >> >>>> to be invoked?
> >> >> >>>
> >> >> >>> You usually should have the request object in your template. See
> >> >> >>>
> >> >> >>>
> https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.path
> >> >> >>> to get the url.
> >> >> >>>
> >> >> >>
> >> >> >> But how do I access that in the template? I tried HttpRequest.path
> >> >> >> and
> >> >> >> {{ HttpRequest.path }} and neither gives me the URL.
> >> >> >
> >> >> > {{ request.path }}
> >> >> > just make sure you have RequestContext if you use
> render_to_response.
> >> >>
> >> >> This is displaying a path, but not the URL I need. It gives
> >> >> /report//EventsTable/ when the URL that's clicked on is:
> >> >>
> >> >>
> >> >>
> >> >>
> http://127.0.0.1/report/Event

Re: Getting URL from within a template

2012-03-13 Thread Furbee
Hi Larry,

render_to_response is one of many ways to return an HttpResponse to send to
the client. Wherever your view does the return, you can pass these GET
variables.

However, if they are being generated by jQuery, dynamically, you should be
using jQuery/javascript to read them and deal with them. This should be
client side javascript code. To read the current URL string in jQuery, I
found a nice little article at
http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html
which
should demonstrate how to get these in javascript on the client-side
browser.

Good luck,

Furbee

On Tue, Mar 13, 2012 at 11:57 AM, Larry Martell wrote:

> On Tue, Mar 13, 2012 at 12:38 PM, Furbee  wrote:
> > I think you want to actually get these in the view code and pass them to
> the
> > template as named variables. For example:
> >
> > return render_to_response('page.htm',
> > {'date_time': request.GET['date_time'], 'submit_preview':
> > request.GET['submit_preview'], 'event_type': request.GET['event_type'],
> > 'filterValue':
> > request.GET['_filterValue']}, context_instance=RequestContext(request))
> >
> > From the template, now, the different variables are available. {{
> date_time
> > }}, {{ submit_preview }}, {{ event_type }}, {{ filterValue }}. That's
> how I
> > would handle it at least.
>
> The URL gets created dynamically by jQuery code in a template. Not all
> these fields are always present. Also, render_to_response is not used. (I'm
> fairly new to both django and this job, and I just grepped through the
> entire code base and it wasn't found.)
>
>
> >
> > Furbee
> >
> > On Tue, Mar 13, 2012 at 11:27 AM, Larry Martell  >
> > wrote:
> >>
> >> On Tue, Mar 13, 2012 at 11:58 AM, Xavier Ordoquy 
> >> wrote:
> >> >
> >> > Le 13 mars 2012 à 18:40, Larry Martell a écrit :
> >> >
> >> >> On Tue, Mar 13, 2012 at 11:26 AM, Xavier Ordoquy <
> xordo...@linovia.com>
> >> >> wrote:
> >> >>> Hi
> >> >>>
> >> >>> Le 13 mars 2012 à 18:11, larry.mart...@gmail.com a écrit :
> >> >>>
> >> >>>> From within a template can I find out the URL that caused the
> >> >>>> template
> >> >>>> to be invoked?
> >> >>>
> >> >>> You usually should have the request object in your template. See
> >> >>>
> https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.path
> >> >>> to get the url.
> >> >>>
> >> >>
> >> >> But how do I access that in the template? I tried HttpRequest.path
> and
> >> >> {{ HttpRequest.path }} and neither gives me the URL.
> >> >
> >> > {{ request.path }}
> >> > just make sure you have RequestContext if you use render_to_response.
> >>
> >> This is displaying a path, but not the URL I need. It gives
> >> /report//EventsTable/ when the URL that's clicked on is:
> >>
> >>
> >>
> http://127.0.0.1/report/EventsTable/?date_time=3y&submit_preview=Generate+Report&event_type=RecipeCreated&_filterValue=dev
> >>
> >> I'm after all the arguments. Is there a way to get them?
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "Django users" group.
> >> To post to this group, send email to django-users@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> django-users+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >> http://groups.google.com/group/django-users?hl=en.
> >>
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/django-users?hl=en.
>
>
>
> --
> Sent from my iPhone
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Getting URL from within a template

2012-03-13 Thread Furbee
I think you want to actually get these in the view code and pass them to
the template as named variables. For example:

return render_to_response('page.htm',
{'date_time': request.GET['date_time'], 'submit_preview':
request.GET['submit_preview'], 'event_type': request.GET['event_type'],
'filterValue':
request.GET['_filterValue']}, context_instance=RequestContext(request))

>From the template, now, the different variables are available. {{ date_time
}}, {{ submit_preview }}, {{ event_type }}, {{ filterValue }}. That's how I
would handle it at least.

Furbee

On Tue, Mar 13, 2012 at 11:27 AM, Larry Martell wrote:

> On Tue, Mar 13, 2012 at 11:58 AM, Xavier Ordoquy 
> wrote:
> >
> > Le 13 mars 2012 à 18:40, Larry Martell a écrit :
> >
> >> On Tue, Mar 13, 2012 at 11:26 AM, Xavier Ordoquy 
> wrote:
> >>> Hi
> >>>
> >>> Le 13 mars 2012 à 18:11, larry.mart...@gmail.com a écrit :
> >>>
> >>>> From within a template can I find out the URL that caused the template
> >>>> to be invoked?
> >>>
> >>> You usually should have the request object in your template. See
> https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.pathto
>  get the url.
> >>>
> >>
> >> But how do I access that in the template? I tried HttpRequest.path and
> >> {{ HttpRequest.path }} and neither gives me the URL.
> >
> > {{ request.path }}
> > just make sure you have RequestContext if you use render_to_response.
>
> This is displaying a path, but not the URL I need. It gives
> /report//EventsTable/ when the URL that's clicked on is:
>
>
> http://127.0.0.1/report/EventsTable/?date_time=3y&submit_preview=Generate+Report&event_type=RecipeCreated&_filterValue=dev
>
> I'm after all the arguments. Is there a way to get them?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Calling "manage.py shell" from the Python Shell in Tutorial Part 1

2012-02-21 Thread Furbee
Python is indentation-specific. It determines the semantics of your code by
it's levels of indentation. For instance:

# print False
if False:
print "false"
print "done"

if False:
print "false"
else:
print "true"

Note that inside the if block, all lines which are indented belong to that
if block. The block ends when the indentation ends. The error
"IndentationError:
unexpected Indent" tells you that Python got an indentation it was not
expecting. This could be as simple as a single space that shouldn't be
there. Check your models.py and settings.py files for any lines that are
indented which are not supposed to be.

Furbee

On Tue, Feb 21, 2012 at 3:41 PM, Django_for_SB wrote:

> Django Gurus,
>
> I'm an absolute beginner using Python in Django. I'm currently going
> through the tutorial, part 1, on the djangoproject.com main website:
> https://docs.djangoproject.com/en/1.3/intro/tutorial01/. I keep trying
> to complete part 1 of the tutorial, step by step, meaning, I'll go
> through the tutorial part 1, progress up to a certain point, then
> close my shell command and shut-down my computer. Then, when I get
> back to opening up the project in which I initially began working on,
> namely, "mysite" (as the tutorial instructs us to name), my shell
> commands aren't valid anymore.
>
> Example:
>
> manage.py shell -> This
> initially works if I start the project from scratch
>
> manage.py shell -> This won't
> work if I leave my project, then go back to continue to
>
> work on it later
>
> This is the error I keep getting:
>
> Traceback(most recent call last):
>
> IndentationError: unexpected Indent
>
>
>
> I'm not quite sure what's going on. Any assistance would be more than
> appreciated. What am I missing here? Thank you.
>
> Best,
>
> SB
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: I am getting TypeError: coercing to Unicode: need string or buffer, long found. Please help.

2012-02-20 Thread Furbee
As an aside, I would assume you want your phone number field to be a string
(models.CharField) instead of integer.

Furbee

On Mon, Feb 20, 2012 at 2:39 PM, Babatunde Akinyanmi
wrote:

> @Daniel
> Your __unicode__ should always return a string  so like Shawn said,
> when you check your phone model, its __unicode__ method should be
> returning str() or unicode() not int
>
> On 2/20/12, Shawn Milochik  wrote:
> > Read the error message in your subject line. Then look at the
> > __unicode__ method of your Phone model. It appears that this is the
> > problem, and not the Device model.
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/django-users?hl=en.
> >
> >
>
> --
> Sent from my mobile device
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: templates not updating when i change things please help

2012-02-19 Thread Furbee
When you make a change to a module (.py) file, you may need to restart your
web server service (Apache2, IIS Service, etc). For template files
(.htm/html) I have never had to restart my server for those changes to be
reflected, so that may be local cache in the browser. Perhaps try using a
new browsing session to remove cache from the picture. In IE, go to File >
New Session, or go to In Private browsing, in Chrome go new Incognito
browser (Ctrl + Shift + N).

That's been my experience, at least.

Furbee

On Sun, Feb 19, 2012 at 6:53 AM, Rich  wrote:

> Hi I am pretty new to django and I feel like I either have some kind
> of configuration wrong or maybe im not understanding how something
> works.
>
> Whats happening is when I make a small change in one of my templates,
> the change is not reflected on my site.
>
> I have noticed that if I make significant changes in one of my views,
> I might see an update in the actual website after reloading the page
> (but it seems to be hit or miss)
>
> If I make only a small change, there is almost never an update to the
> actual website unless it is a change within a view.
>
> Changing some text within a template file yields no results.
>
> If I mess up some code i will get debugging messages, but if I fix the
> code, I get the same (cached?) result
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: DATABASE in settings file not working

2012-02-17 Thread Furbee
That is strange. This probably won't help, but try deleting the
settings.pyc file and then run python manage.py runserver again (without
--settings=settings).

Furbee

On Fri, Feb 17, 2012 at 7:45 AM, Babatunde Akinyanmi
wrote:

> Yes I do get it. I didn't realize that while I was typing my reply
> your message had already been delivered to the group.
>
> On 2/17/12, Detectedstealth  wrote:
> > I can connect with the same credentials that isn't the problem.
> >
> > The problem is if I set a password in settings.py it doesn't use a
> > password as the error message states. However when I force the
> > settings file with the --settings option then it reads the file
> > correctly and uses the password.
> >
> > On Feb 17, 7:06 am, Babatunde Akinyanmi  wrote:
> >> Try to connect to mysql with the same credentials on your terminal. If
> >> it doesn't work then you need to reset your root password.
> >>
> >> sudo dpkg-reconfigure mysql-server-5.1
> >>
> >> Should do the trick and then restart the server (That works on ubuntu).
> >>
> >> Also you should consider creating a separate user instead of using root.
> >>
> >> On 2/17/12, Detectedstealth  wrote:
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> > Hi,
> >>
> >> > I am just coming back to django development after a while of
> >> > developing with pyramid. I have taking over an application.
> >>
> >> > For some reason with the newest version of django it is not reading
> >> > the password I set in settings:
> >>
> >> > DATABASES = {
> >> > 'default': {
> >> > 'ENGINE': 'django.db.backends.mysql', # Add
> >> > 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
> >> > 'NAME': 'mydatabase',  # Or path to
> >> > database file if using sqlite3.
> >> > 'USER': 'root',  # Not used with sqlite3.
> >> > 'PASSWORD': 'mypassword',  # Not used with
> >> > sqlite3.
> >> > 'HOST': '',  # Set to empty string for
> >> > localhost. Not used with sqlite3.
> >> > 'PORT': '',  # Set to empty string for
> >> > default. Not used with sqlite3.
> >> > }
> >> > }
> >>
> >> > When starting the server I get the following error:
> >> > ...MySQL_python-1.2.3-py2.7-linux-x86_64.egg/MySQLdb/connections.py",
> >> > line 187, in
> >> > __init__
> >> > _mysql_exceptions.OperationalError: (1045, "Access denied for user
> >> > 'root'@'localhost' (using password: NO)")
> >>
> >> > Not sure why it is saying there was not password. For the newest
> >> > version of django is there a new way to tell python manage.py
> >> > runserver what password/username/database to use?
> >>
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> > Groups
> >> > "Django users" group.
> >> > To post to this group, send email to django-users@googlegroups.com.
> >> > To unsubscribe from this group, send email to
> >> > django-users+unsubscr...@googlegroups.com.
> >> > For more options, visit this group at
> >> >http://groups.google.com/group/django-users?hl=en.
> >>
> >> --
> >> Sent from my mobile device
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/django-users?hl=en.
> >
> >
>
> --
> Sent from my mobile device
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Dumb newbie question

2012-02-17 Thread Furbee
Yes, they just need to import the models from the module that they need. Be
aware, of circular imports, though. That is when one module imports from
another which also imports from the first one. Check the imports at the top
to make sure the module from which you are importing classes, modles, defs,
constants, does not import anything from the module that you are importing
into. Funny things happen, when you have circular imports, and when you are
beginning out they can be hard to troubleshoot.

Furbee


On Fri, Feb 17, 2012 at 7:43 AM, Bob Carlson  wrote:

> I’m well into beginning building my actual app after going through the
> tutorial, but I have no feel yet for the answer to this question.
>
> ** **
>
> Can apps share a set of models? My application neatly divides into three
> pieces, but all the pieces share the same data. Should these be 3 apps or
> 1? Can apps freely share access to data models?
>
> ** **
>
> Cheers, Bob
>
> ** **
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: import problem

2012-02-17 Thread Furbee
Good point, Dennis. I use Apache2, and any time I modify .py files, I need
to restart the Apache2 daemon. I wish I didn't have to, but the environment
needs to be flushed. Luckily, it doesn't kill the sessions or anything
like, say ColdFusion when it restarts. I was wondering if there was
something with your environment that was using an old copy of the file
without the import, because your syntax sounded perfect. Anyway, I'm glad
you got it figured out!

Furbee

On Thu, Feb 16, 2012 at 6:33 PM, Dennis Lee Bieber wrote:

> On Thu, 16 Feb 2012 21:00:40 -0500, Scott Macri 
> wrote:
>
>
> >Do I need to close IDLE every time I modify one of my object classes
> >being accessed?  I've just been recreating the object in IDLE and not
> >closing the window.  Any thoughts on this?  Thanks.
>
> If the file needs to be imported -- doing edit file/save file/
> "import file", won't affect anything that has references to the previous
> edition of the file. Heck, just "import file" on the second import won't
> do anything -- Python will find that "file" has already been imported
> and reference that module. You have to use a reload operation to get
> changed modules to import a second time. But even this only replaces
> stuff for NEW references; any other references won't see the new
> version.
>
>This is especially true if you are testing in the interactive shell.
> You need to spawn a totally new process to ensure a clean environment
> (which is why some of us keep a command line open next to the
> environment we use for editing [PythonWin, in my case -- I never could
> get comfortable with IDLE]. We edit the file in the IDE, save it, and
> switch to the command shell to run the program cleanly.
> --
>Wulfraed Dennis Lee Bieber AF6VN
>wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: import problem

2012-02-16 Thread Furbee
He said he would do that later tonight.

Furbee

On Thu, Feb 16, 2012 at 2:04 PM, Dennis Lee Bieber wrote:

> On Thu, 16 Feb 2012 13:41:32 -0500, Scott Macri 
> wrote:
>
> >I don't believe I have any circular imports in my code.  I have a
> >simple file dosomething.py, with a simple class containing a simple
> >function.
>
> You have yet to show (at least, in the history I've seen) the exact
> traceback of the error.
>
> --
>Wulfraed Dennis Lee Bieber AF6VN
>wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: import problem

2012-02-15 Thread Furbee
Can you reply with the actual NameError Exception? Like: NameError: globalname
'datetime' is not defined, or whatever it is. From the module that is
throwing this error are you importing anything else that is importing an
overridden date method or datetime object?

You can also try this (instead of "import datetime"):

from datetime import date

On Wed, Feb 15, 2012 at 7:48 PM, Scott  wrote:

> Hello,
> I'm having a strange issue and have already spent an hour trying to
> figure it out.
>
> I created a python app called mn.  Then I setup all my models and
> stuff to work under mn.hcp.  Everything has been working fine until I
> tried to use date time in a py file in the hcp directory.
>
> I've imported datetime, with import date time at the top of my py
> file.  Then within the file I have a class with an internal method
> trying to use some date functions.
>
> datetime.date(2003,11,11)
>
> For some reason I am getting a NameError on the datetime object.  I
> don't understand why this is happening after I've imported datetime.
> Any help would be appreciated.  Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Where are the 2+ places user_id is defined?

2012-02-15 Thread Furbee
Did you try Alasdair's answer from the question you posed on StackOverflow (
http://stackoverflow.com/questions/9302434/when-i-try-a-syncdb-where-is-the-duplicate-user-id-error-coming-from
)?

Syncdb is trying to create a new superuser, but it fails when it creates
the related user profile because there is already a user profile with that
user_id in the database.

If you are currently developing, then the easiest thing to do is to drop
the user profile table and let syncdb recreate it. Alternatively you could
delete the unneeded user profiles in the shell.

Furbee

On Wed, Feb 15, 2012 at 3:49 PM, Christos Jonathan Hayward <
christos.jonathan.hayw...@gmail.com> wrote:

> P.S. The source is at http://JonathansCorner.com/project/pim.tgz.
>
>
> On Wed, Feb 15, 2012 at 3:40 PM, Christos Jonathan Hayward <
> christos.jonathan.hayw...@gmail.com> wrote:
>
>> I forgot to specify where. The traceback is on a '''python manage.py
>> syncdb''', and happens immediately after the password is entered twice.
>>
>>
>> On Wed, Feb 15, 2012 at 3:39 PM, Christos Jonathan Hayward <
>> christos.jonathan.hayw...@gmail.com> wrote:
>>
>>> I'm getting an error:
>>>
>>> Traceback (most recent call last):
>>>   File "manage.py", line 14, in 
>>> execute_manager(settings)
>>>   File
>>> "/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/core/management/__init__.py",
>>> line 438, in execute_manager
>>> utility.execute()
>>>   File
>>> "/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/core/management/__init__.py",
>>> line 379, in execute
>>> self.fetch_command(subcommand).run_from_argv(self.argv)
>>>   File
>>> "/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/core/management/base.py",
>>> line 191, in run_from_argv
>>> self.execute(*args, **options.__dict__)
>>>   File
>>> "/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/core/management/base.py",
>>> line 220, in execute
>>> output = self.handle(*args, **options)
>>>   File
>>> "/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/core/management/base.py",
>>> line 351, in handle
>>> return self.handle_noargs(**options)
>>>   File
>>> "/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/core/management/commands/syncdb.py",
>>> line 109, in handle_noargs
>>> emit_post_sync_signal(created_models, verbosity, interactive, db)
>>>   File
>>> "/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/core/management/sql.py",
>>> line 190, in emit_post_sync_signal
>>> interactive=interactive, db=db)
>>>   File
>>> "/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/dispatch/dispatcher.py",
>>> line 172, in send
>>> response = receiver(signal=self, sender=sender, **named)
>>>   File
>>> "/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py",
>>> line 70, in create_superuser
>>> call_command("createsuperuser", interactive=True)
>>>   File
>>> "/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/core/management/__init__.py",
>>> line 166, in call_command
>>> return klass.execute(*args, **defaults)
>>>   File
>>> "/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/core/management/base.py",
>>> line 220, in execute
>>> output = self.handle(*args, **options)
>>>   File
>>> "/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/contrib/auth/management/commands/createsuperuser.py",
>>> line 134, in handle
>>> User.objects.create_superuser(username, email, password)
>>>   File
>>> "/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/contrib/auth/models.py",
>>> line 140, in create_superuser
>>> u = self.create_user(username, email, password)
>>>   File
>>> "/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/contrib/auth/models.py",
>>> line 136, in create_user
>>> user.save(using=self._db)
>>>   File
>>> "/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/db/models/base.py",
>>> line 460, in save
>>> self.save_base(using=using, force_insert=force_insert

Re: What is the best type of wood to use for staking vampires?

2012-02-15 Thread Furbee
Ha ha ha, that's funny!

On Wed, Feb 15, 2012 at 12:44 PM, James Pyrich  wrote:

> On 2/15/12 1:28 PM, Dennis Lee Bieber wrote:
>
>> On Wed, 15 Feb 2012 11:45:51 -0800, Furbee
>> wrote:
>>
>>  Is this posting a zombie? It doesn't seem to ever die no matter what we
>>> do
>>> to kill it! :-)
>>>
>>> More like a vampire -- we dispose of it, and then sometime later
>> someone pulls the stake out of the corpse and it comes back to drain the
>> life force of some newsgroup...
>>
> I think cedar is best though I have heard good things about hickory...
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@**
> googlegroups.com .
> For more options, visit this group at http://groups.google.com/**
> group/django-users?hl=en<http://groups.google.com/group/django-users?hl=en>
> .
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: what is the best IDE to use for Python / Django

2012-02-15 Thread Furbee
Is this posting a zombie? It doesn't seem to ever die no matter what we do
to kill it! :-)

Furbee

On Wed, Feb 15, 2012 at 10:09 AM,  wrote:

> **
> @Sanders, nice answer :D, SOL
> +adesst
> --
> *From: * Thorsten Sanders 
> *Sender: * django-users@googlegroups.com
> *Date: *Wed, 15 Feb 2012 17:32:29 +0100
> *To: *
> *ReplyTo: * django-users@googlegroups.com
> *Subject: *Re: what is the best IDE to use for Python / Django
>
> Why this kind of stuff never ends?;(
>
> The best IDE is simply the one you can work best with, YOURSELF!
>
> On 15.02.2012 16:13, Vikas Ruhil wrote:
>
> Vim is best IDE for Python/Django ! look here the link
> http://learnhackstuff.blogspot.in/2012/02/vim-as-universal-idepart-1.html
>
> On Wed, Feb 15, 2012 at 8:16 PM, Bastian Ballmann <
> bastian.ballm...@notch-interactive.com> wrote:
>
>> Hey thats a cool list and I feel like I must answer on it :)
>>
>>
>> Am 01.02.2012 17:43, schrieb Masklinn:
>>
>>> On 2012-02-01, at 17:00 , Bastian Ballmann wrote:
>>>
>>>> And what exact feature makes PyCharm an IDE that emacs hasnt?
>>>>
>>> * Semantics navigation (not via tags, it knows to find a class when you
>>> want a class)
>>>
>> I heard ECB can do this, but I dont use it
>>
>>
>>  * Better static analysis and language knowledge (the type inference is
>>> still pretty limited, but if you instantiate an object and call a method on
>>> it it knows and only proposes the available methods)
>>>   - virtualenv-aware, knows to restrict its libraries search to the
>>> project's virtualenv
>>>
>> You can do this with setenv or virtualenv.el too
>>
>>
>>- errors and warnings are faster to display than via flymake in my
>>> experience
>>>
>> For me flymake is faster *g*
>>
>>- also intentions and quickfixes, PyCharm can improve or simplify code
>>> for known bad or sub-par patterns, and can fix a limited number of errors
>>> (PyCharm will suggest importing a module you reference without you having
>>> to go to the module top and doing so manually)
>>>
>>
>> Autoimport can be done with rope-auto-import
>>
>>
>>- finds all references to an object
>>>
>>
>> And this one with rope-find-occurrences
>>
>>
>>  * Much, much better (faster, more expansive and with less bullet holes)
>>> refactoring support than Rope&  ropemacs (I use both)
>>> * Good support of various template languages (Django, Jinja2 and Mako as
>>> of 2.0) with autocompletion, basic static analysis, syntax highlighting,
>>> etc…
>>>
>> Yeah that's something I miss, but auto-completion for Django template
>> code is available in django-mode
>>
>>
>>  * Semantic knowledge of Django projects
>>>   - jumping between a view and its template
>>>
>>
>> This can also be done with django-mode
>>
>>
>>  * Much better debugging story
>>>   - Pretty good visual debugger with watches and conditional breakpoints
>>>   - Remote debugger (via a specific agent)
>>>
>>
>> Therefore I use pddb outside of Emacs
>>
>>- Django templates debugging
>>>
>> Yep that's also something I miss. Can partly be done with Werkzeug in the
>> browser
>>
>> For me Emacs has the far better editing features than the Eclipse editor
>> with stuff like rectangle edit,
>> macros and the like and it's very good extensible and therefore can
>> perfectly adapted to one's needs.
>> Greets
>>
>> Basti
>>
>> --
>> Bastian Ballmann / Web Developer
>> Notch Interactive GmbH / Badenerstrasse 571 / 8048 Zürich
>> Phone +41 43 818 20 91 / www.notch-interactive.com
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at

Re: Speficy a Database for Testing

2012-02-08 Thread Mark Furbee
I'm not sure that you can specify a different existing database. I think
(not certain) that Django's testing is built to have no effect on real
data, hence creating a blank test database. You can, however, use fixtures
to create data in the test database after it is created and before the unit
tests are performed. I assume the reason you want to use a previously,
externally created DB is that you want to test based on the data in that
DB. If this is the case, it is perfect to use a fixture of that DB's data.

Mark

On Wed, Feb 8, 2012 at 7:42 AM, xina towner  wrote:

> Yes, but django makes a new testDatabase and that's my problem, I want
> django to use a database I've previously done.
>
>
> On 8 February 2012 16:34, Mark Furbee  wrote:
>
>> Denis Darii already answered this on February 1st:
>>
>> "You can redefine your database connection by adding somewhere at the
>> end of your settings.py something like:
>>
>> import sys
>>
>> if 'test' in sys.argv:
>>
>> DATABASES = ...
>>
>> hope this helps."
>>
>>
>> Did you try this?
>>
>> On Wed, Feb 8, 2012 at 7:19 AM, xina towner  wrote:
>>
>>> Can I create a Database manually and then specify to the testing unit to
>>> use that?
>>>
>>> --
>>> Gràcies,
>>>
>>> Rubén
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>
>
> --
> Gràcies,
>
> Rubén
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Speficy a Database for Testing

2012-02-08 Thread Mark Furbee
Denis Darii already answered this on February 1st:

"You can redefine your database connection by adding somewhere at the end
of your settings.py something like:

import sys

if 'test' in sys.argv:

DATABASES = ...

hope this helps."


Did you try this?

On Wed, Feb 8, 2012 at 7:19 AM, xina towner  wrote:

> Can I create a Database manually and then specify to the testing unit to
> use that?
>
> --
> Gràcies,
>
> Rubén
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: create users from /etc/passwd?

2012-02-02 Thread Furbee
Hi Tim,

I'm not totally sure, but I don't think this will work. You could parse the
passwd file to get the usernames, but the passwords are encrypted. Since
you don't have the system's decryption key, you would not be able to
determine the password. If you just used what is in /etc/shadow it would
not match the password that the users enter when they try to authenticate
in Django.

I would suggest using Django's built-in authentication system. Then when a
user goes to your site, and enters their credentials, you will be able to
access the user information in the view with request.user (assuming
"request" is your view's first parameter name).

Django's documentation is a lifesaver, here's setting up User
Authentication:
https://docs.djangoproject.com/en/1.3/topics/auth/

Here's accessing session information when a user is logged in.
https://docs.djangoproject.com/en/1.3/topics/http/sessions/

Finally, you can use the decorator @login_required for views that require
authentication. However, I found it easier for many applications that use
site-wide authentication (usually the case with intranet development) to
use middleware to require login for every page. I implemented something
similar to this and it works perfectly.:
http://onecreativeblog.com/post/59051248/django-login-required-middleware

You're want to study up on how middleware works, here:
https://docs.djangoproject.com/en/1.3/topics/http/middleware/


Good Luck,

Furbee

On Thu, Feb 2, 2012 at 7:47 AM, Tim  wrote:

> I'm running Django 1.3.1 on FreeBSD + Apache2.2 inside an intranet.
>
> I do not grok authentication, so here is my problem and a question about
> how I can solve it (maybe).
> What I need is the name of the user who hits the application. I don't care
> about the password, I just need to know who they are. I've been unable to
> get the REMOTE_USER from Apache, mainly because I think Apache doesn't know
> it either (no authentication is used on the httpd.conf).
>
> I thought (here's my maybe solution) I might create a bunch of users in
> Django by parsing the /etc/passwd database. Then at least each user would
> have the same username/password they use to login to the network.
>
> Is that possible? Is there a better way to get the username?
> thanks,
> --Tim
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/qO-mxTOE0joJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Testing

2012-01-31 Thread Furbee
I think you can do something like:
assertTrue(first == one_value or first == second_value)

At the same time, when unit testing, you should really know exactly what a
value returned from a method is.

Furbee

On Tue, Jan 31, 2012 at 4:32 PM, xino12  wrote:

> Hello, I'm doing unitTesting and I want to know if it's possible to
> accept more than one value in the assetEqual method.
>
> Maybe this works
>
> assertEqual(first, one_value or another_value)
>
> Sorry but I'm new programming with django.
>
> Lots of thanks,
>
> Rubén
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Having Headache With LoginForm

2012-01-19 Thread Mark Furbee
No problem. You will likely use the form objects in your template, I just
chose to create my own form in HTML.

Since the 'views.Login' is a string, you don't need to import it. It just
tells Django which view to pass the request to when that url pattern is
found. The ^ means the beginning of the url after the slash
(www.mysite.com/). The $ means the string ends. I found this useful, because without
it, multiple urls will match. For example: with `url(r'^login',
'views.Login')`, the following will all match and go to views.Login: 1)
www.mysite.com/login, 2) www.mysite.com/login_page, 3)
www.mysite.com/login?no_login=1. So I specify the $ to make it more exact,
more out of habit than requirement. If you add the slash to the end like
`url(r'^login/$', 'views.Login')`, it will require the slash, so
www.mysite.com/login will not match. If you want to have both urls work, I
think this will work (although untested): `url(r'^login/?$',
'views.Login')`, where the /? means that there could be no / or one slash.
With this, the following would not match: www,mysite.com/login///. If you
wanted to allow multiple slashes, change the ? with *, like
`url(r'^login/*', 'views.Login')`. Again, that's not tested, but it should
work, I think.

Happy Coding!

Mark

On Wed, Jan 18, 2012 at 6:09 PM, coded kid  wrote:

> Thanks bro. Don't you think I should import Login in urls.py? What
> about / in before the $ in urls.py? Or I should just place it like
> that?
>
> Mark Furbee wrote:
> > This is my login process.
> >
> > urls.py:
> > url(r'^login$', 'views.Login'),
> > url(r'^logout$', 'views.Logout'),
> >
> >
> > views.py:
> > def Login(request, next=None):
> > """
> > Used to log into the application.
> > """
> >
> > #  If the user is authenticated pass them through to the homepage.
> > if request.user.is_authenticated():
> > return HttpResponseRedirect('/')
> >
> > # If the user is not authenticated, but the method is POST, they have
> > posted their username and password.
> > if request.method == "POST":
> >
> > # Get Username and Password.
> > username = request.POST['username']
> > password = request.POST['password']
> >
> > # Authenticate.
> > user = authenticate(username=username, password=password)
> >
> > # If the User is not None, they have a valid account and
> password.
> > if user is not None:
> >
> > # If the user isactive, we can log them in.
> > if user.is_active:
> > # Log them in, and redirect to the homepage.
> > login(request, user)
> > return HttpResponseRedirect('/')
> >
> > # If the user is not active, pass them back to the login
> page,
> > with a message that the account is inactive.
> > else:
> > return render_to_response('login.htm', {'error': 'Account
> > Disabled - contact I.T. for assistance'},
> > context_instance=RequestContext(request))
> >
> > # The user with those credentials did not exist, pass them back
> to
> > the login page, with a message that the account was invalid.
> > else:
> > return render_to_response('login.htm', {'error': 'Invalid
> > Username/Password - contact I.T. for assistance'},
> > context_instance=RequestContext(request))
> >
> > # They have not yet attempted a login, pass them to the login page,
> > without any error messages..
> > else:
> >
> > return render_to_response('login.htm', {'NoSessionTimeout':
> 'True',
> > 'next': next}, context_instance=RequestContext(request))
> >
> >
> > def Logout(request):
> > logout(request)
> >
> > # Render the logout.htm page, which will display they are logging out
> > and redirect them to the login page.
> > return render_to_response('login.htm', {'notice': 'You have been
> logged
> > out successfully.'}, context_instance=RequestContext(request))
> >
> >
> >
> > template login.htm:
> >
> > .
> > .
> > .
> >  > method="post" name="login">
> >  {% csrf_token %}
> >  
> >  
> >  Login
> >  
> &g

Re: Having Headache With LoginForm

2012-01-18 Thread Mark Furbee
This is my login process.

urls.py:
url(r'^login$', 'views.Login'),
url(r'^logout$', 'views.Logout'),


views.py:
def Login(request, next=None):
"""
Used to log into the application.
"""

#  If the user is authenticated pass them through to the homepage.
if request.user.is_authenticated():
return HttpResponseRedirect('/')

# If the user is not authenticated, but the method is POST, they have
posted their username and password.
if request.method == "POST":

# Get Username and Password.
username = request.POST['username']
password = request.POST['password']

# Authenticate.
user = authenticate(username=username, password=password)

# If the User is not None, they have a valid account and password.
if user is not None:

# If the user isactive, we can log them in.
if user.is_active:
# Log them in, and redirect to the homepage.
login(request, user)
return HttpResponseRedirect('/')

# If the user is not active, pass them back to the login page,
with a message that the account is inactive.
else:
return render_to_response('login.htm', {'error': 'Account
Disabled - contact I.T. for assistance'},
context_instance=RequestContext(request))

# The user with those credentials did not exist, pass them back to
the login page, with a message that the account was invalid.
else:
return render_to_response('login.htm', {'error': 'Invalid
Username/Password - contact I.T. for assistance'},
context_instance=RequestContext(request))

# They have not yet attempted a login, pass them to the login page,
without any error messages..
else:

return render_to_response('login.htm', {'NoSessionTimeout': 'True',
'next': next}, context_instance=RequestContext(request))


def Logout(request):
logout(request)

# Render the logout.htm page, which will display they are logging out
and redirect them to the login page.
return render_to_response('login.htm', {'notice': 'You have been logged
out successfully.'}, context_instance=RequestContext(request))



template login.htm:

.
.
.

 {% csrf_token %}
 
 
 Login
 

 
{% if error %}
 

 {% FatalImage %}
{{ error }}

 

 {% endif %}
{% if warning %}

 
{% WarnImage %}
 {{ warning }}


 
{% endif %}
 {% if notice %}


 {% NoticeImage %}
{{ notice }}

 

 {% endif %}

Email address:    
 

 


 Password:    

 
 

 
 
 

 

 


 




On Wed, Jan 18, 2012 at 8:09 AM, Mark Furbee  wrote:

> Is that template mainpage.html?
>
> I'm not sure exactly what you mean is happening. When you open the login
> page it takes you back to the home page? Also, I would add in the my_login
> view that if they are already logged in to redirect them to another page
> besides the login page. As your view is now, when they go to the login
> page, while they are already logged in, it will allow them to log in again
> as a different user. Perhaps that is intended, I just thought I'd point it
> out.
>
> Mark
>
> On Tue, Jan 17, 2012 at 10:57 PM, coded kid wrote:
>
>> Yeah, I've done that, but its not working! Any help?
>>
>> On Jan 17, 10:37 pm, Mark Furbee  wrote:
>> > It means, don't use the "decorator" @login_required above your login
>> view.
>> > Your login view cannot require a login, because you'd never get to log
>> in.
>> > Chicken and egg.
>> >
>> >
>> >
>> > On Tue, Jan 17, 2012 at 2:34 PM, coded kid 
>> wrote:
>> >
>> > > Thorsten Sanders wrote:
>> > > > With using
>> >
>> > > > @login_required decorator the user needs to be logged in to allow
>> > > execution, don't makes much sense for a login :P
>> >
>> > > > Am 17.01.2012 22:23, schrieb coded kid:
>> > > > > Hi guys, I�m having problem with my login form. The login form
>> will
>> > > > > redirect me to the next page even if I didn�t input anything in
>> the
>> > > > > username and password field. Also it can�t get the username of
>> the
>> > > > > registered users to verify if the user data is wrong or right.
>> How can
>> > > > > I get rid of this problem?
>> > > > > Below are my code:
>> > > > > In views.py
>> > > > > from django.db import models
>> > > > > from mymeek.meek

Re: Having Headache With LoginForm

2012-01-18 Thread Mark Furbee
Is that template mainpage.html?

I'm not sure exactly what you mean is happening. When you open the login
page it takes you back to the home page? Also, I would add in the my_login
view that if they are already logged in to redirect them to another page
besides the login page. As your view is now, when they go to the login
page, while they are already logged in, it will allow them to log in again
as a different user. Perhaps that is intended, I just thought I'd point it
out.

Mark

On Tue, Jan 17, 2012 at 10:57 PM, coded kid  wrote:

> Yeah, I've done that, but its not working! Any help?
>
> On Jan 17, 10:37 pm, Mark Furbee  wrote:
> > It means, don't use the "decorator" @login_required above your login
> view.
> > Your login view cannot require a login, because you'd never get to log
> in.
> > Chicken and egg.
> >
> >
> >
> > On Tue, Jan 17, 2012 at 2:34 PM, coded kid 
> wrote:
> >
> > > Thorsten Sanders wrote:
> > > > With using
> >
> > > > @login_required decorator the user needs to be logged in to allow
> > > execution, don't makes much sense for a login :P
> >
> > > > Am 17.01.2012 22:23, schrieb coded kid:
> > > > > Hi guys, I�m having problem with my login form. The login form
> will
> > > > > redirect me to the next page even if I didn�t input anything in
> the
> > > > > username and password field. Also it can�t get the username of
> the
> > > > > registered users to verify if the user data is wrong or right. How
> can
> > > > > I get rid of this problem?
> > > > > Below are my code:
> > > > > In views.py
> > > > > from django.db import models
> > > > > from mymeek.meekme.models import RegisterForm
> > > > > from django.shortcuts import render_to_response
> > > > > from django.http import HttpResponse
> > > > > from django.template import RequestContext
> > > > > from django.http import HttpResponseRedirect
> > > > > from django.contrib.auth import authenticate, login
> > > > > from django.contrib.auth.decorators import login_required
> >
> > > > > @login_required
> > > > > def mylogin(request):
> > > > >  if request.method=='POST':
> > > > >  username= request.POST['username']
> > > > >  password= request.POST['password']
> > > > >  user=authenticate (username=username, password=password)
> > > > >  if user is not None:
> > > > >  if user.is_active:
> > > > >  login(request, user)
> > > > >  return HttpResponseRedirect('/logpage/')
> > > > >  else:
> > > > >  return direct_to_template(request,'q_error.html')
> > > > >  else:
> > > > >  return render_to_response('mainpage.html')
> > > > > In my template:
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > >{{form.username.label_tag}}
> > > > >{{form.username}}
> > > > > 
> > > > > 
> > > > >{{form.password.label_tag}}
> > > > >{{form.password}}
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > > Please help me out! Thanks.
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Django users" group.
> > > To post to this group, send email to django-users@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group at
> > >http://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Having Headache With LoginForm

2012-01-17 Thread Mark Furbee
It means, don't use the "decorator" @login_required above your login view.
Your login view cannot require a login, because you'd never get to log in.
Chicken and egg.

On Tue, Jan 17, 2012 at 2:34 PM, coded kid  wrote:

>
>
> Thorsten Sanders wrote:
> > With using
> >
> > @login_required decorator the user needs to be logged in to allow
> execution, don't makes much sense for a login :P
> >
> >
> >
> > Am 17.01.2012 22:23, schrieb coded kid:
> > > Hi guys, I�m having problem with my login form. The login form will
> > > redirect me to the next page even if I didn�t input anything in the
> > > username and password field. Also it can�t get the username of the
> > > registered users to verify if the user data is wrong or right. How can
> > > I get rid of this problem?
> > > Below are my code:
> > > In views.py
> > > from django.db import models
> > > from mymeek.meekme.models import RegisterForm
> > > from django.shortcuts import render_to_response
> > > from django.http import HttpResponse
> > > from django.template import RequestContext
> > > from django.http import HttpResponseRedirect
> > > from django.contrib.auth import authenticate, login
> > > from django.contrib.auth.decorators import login_required
> > >
> > > @login_required
> > > def mylogin(request):
> > >  if request.method=='POST':
> > >  username= request.POST['username']
> > >  password= request.POST['password']
> > >  user=authenticate (username=username, password=password)
> > >  if user is not None:
> > >  if user.is_active:
> > >  login(request, user)
> > >  return HttpResponseRedirect('/logpage/')
> > >  else:
> > >  return direct_to_template(request,'q_error.html')
> > >  else:
> > >  return render_to_response('mainpage.html')
> > > In my template:
> > > 
> > > 
> > > 
> > > 
> > >{{form.username.label_tag}}
> > >{{form.username}}
> > > 
> > > 
> > >{{form.password.label_tag}}
> > >{{form.password}}
> > > 
> > > 
> > > 
> > > 
> > > 
> > > Please help me out! Thanks.
> > >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Need to examine and act on old vs. new at .save() time

2012-01-12 Thread Furbee
The only other way that I could think to do it would be to write your own
M2M object. Just an object with two foreign key fields to reference X and
Y. In that object you could overwrite the save method to check for which
relations currently exist for a given reference to X and update
accordingly. I'm not sure this would work for you, but it might be an
alternative, although it violates the DRY principle.

Furbee

On Thu, Jan 12, 2012 at 9:20 AM, Jeff  wrote:

>
> On Jan 11, 9:23 pm, Dennis Lee Bieber  wrote:
> > On Wed, 11 Jan 2012 17:26:44 +, Tom Evans 
> > wrote:
> >
> > >On Wed, Jan 11, 2012 at 5:22 PM, Jeff  wrote:
> > >> When Device.netgroups (a M2M field) changes, we need to perform
> > >> some python-ldap operations.
> >
> > >Have you considered simply going back to the database to check what
> > >the values currently are? It would be inefficient, but clean and
> > >concise.
> >
> > I've forgotten how many means of changing this data there are,
> > but...
>
> Dennis,
>
> Several.
>
> A web-only solution won't work.
>
> I found the 'm2m_changed' signal yesterday, read that you can't
> determine *what* changed by using it, and also ended up directed
> to some open bug reports... etc... and threw up my hands.
>
> To the best of my digging, there is no way to accurately tell
> in SomeModel.save() whether the previous value of MyM2MField
> and the new value are the same, and/or what the differences
> are.
>
> I ended up completely restructuring stuff (I'll spare you the
> details) so that I can just say "whatever .netgroups looks
> like AFTER save, make LDAP look exactly like that."  This
> is essentially what Tom Evans suggested in his reply.  It's
> inefficient, and clearly a workaround, but is at least doable.
>
> It boils down in LDAP-terms to saying "replace all attribute
> values for X with the following full data.  I don't care what
> your old data was."  ... instead of saying, "remove value Y
> from the 1000 values set on X"  :|
>
> Thank you all for your efforts to help.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: no plus-sign to add related object in admin

2011-12-29 Thread Furbee
Just taking a stab in the dark, are the ones without the + sign editable in
the Admin? If they are not editable, I would imagine Django would not show
the + in the Admin.

Furbee

On Thu, Dec 29, 2011 at 12:58 PM, K.C. Smith  wrote:

> I've got a project where when I pull up the admin page to add an
> object (an object that has several foreign keys), some of the FK
> fields show the little green plus-sign links to add a new related
> object for that field and other FK fields do not.
>
> In the past, I've seen the plus-sign link to add a new related object
> on all of the FK fields.  Why would it not show up?
>
> I'm using Django 1.2.5.
>
> K.C.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Successful login to go back to the page login was initiated from

2011-12-16 Thread Furbee
Thanks for sharing the answer, I was sort of wanting to figure this out
long term, just haven't gotten to it, yet.

Furbee

On Fri, Dec 16, 2011 at 4:33 PM, bazaarsoft  wrote:

> Never mind, found the answer:
>
> http://efreedom.com/Question/1-806835/Django-Redirect-Previous-Page-Login
>
> My Google-fu must be off today.
>
> On Dec 16, 6:00 pm, bazaarsoft  wrote:
> > I have what appears to be an odd case - I have a login link on a bunch
> > of pages (logout if you're already logged in). What I want is to use
> > the built-in contrib.auth stuff to handle the login, but I want it to
> > take me back to the originating page once the user gets logged in
> > correctly. Unfortunately, I can't seem to find a single place to kick
> > the machine to make this happen. Is it possible with some simple
> > config or do I really have to implement my own forms/views?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Can a template extend a template?

2011-12-13 Thread Furbee
Brilliant! I wasn't looking an answer to this question, and wasn't all that
aware of how these interacted, but it will sure come in handy. Thanks for
the extremely clear, concise explanation. I don't think the Django docs
make it quite that clear.

Furbee

On Tue, Dec 13, 2011 at 3:49 PM, Russell Keith-Magee <
russ...@keith-magee.com> wrote:

> On Wed, Dec 14, 2011 at 6:21 AM, Jason <1jason.whatf...@gmail.com> wrote:
> > Hi there,
> >
> > I love the concept of DRY, and django's enthusiasm for this concept. In
> > light of this I have tried to have a template extend a template, but it
> > doesn't seem to work. Is there a better way than what I'm currently
> doing?
>
> Yes :-)
>
> > The current way
> >
> > index.html
> >
> > {% if current_user %}
> > {% extends "_logged_out_template.html" %}
> >
> > {% else %}
> > {% extends "_logged_in_template.html" %}
> > {% endif %}
> >
> > contact.html
> >
> > {% if current_user %}
> >
> > {% extends "_logged_out_template.html" %}
> >
> > {% else %}
> >
> > {% extends "_logged_in_template.html" %}
> >
> > {% endif %}
> >
> >
> >
> > The way I would like it to be (but it didn't work)
> >
> > index.html
> > {% extends "_base_template.html" %}
> >
> > _base_script.html
> >
> > {% if current_user %}
> >
> > {% extends "_logged_out_template.html" %}
> >
> > {% else %}
> >
> > {% extends "_logged_in_template.html" %}
> >
> > {% endif %}
>
> This sample suggests that you may have some misunderstandings about
> how Django's template language -- and the {% extends %} tag in
> particular -- are supposed work.
>
> {% extends %} is *not* the same as {% include %}. A template can only
> *extend* a single other template. The natural partner of {% extends %}
> is the {% block %} tag.
>
> Django also has an {% include %} statement, but {% extends %} and {%
> block %} are generally more efficient (and, in my experience,
> flexible)
>
> {% extends %} is the only special case in Django's template parser.
> The extends tag is parsed separately from the rest of the tags
> (specifically so that it can interact with {% block %} tags), and as a
> result, the {% block %} tag doesn't interact with {% if %} or other
> logical constructs. The Django parser works out what templates are
> being extended, creating a single template, and *then* sorts out the
> page logic.
>
> Working with an {% include %} tag is a bit like a "top down" design --
> you have a final product in mind, which you construct by assembling
> lots of smaller snippets. {% extends %} is more like a bottom up
> design -- you establish a basic structure, and then work out how a
> specific page modifies the basic structure.
>
> Looking at your example, it's not entirely clear what you're trying to
> achieve; hopefully the following example will give you an idea of how
> {% extends %} and {% block %} work together:
>
> base.html:
>
> {% block header %}My Site{% endblock %}
> {% block body %}{% endblock %}
> {% block footer %}Thanks for coming{% endblock %}
>
> index.html
> {% extends "base.html" %}
> {% block body %}
> This is the index
> {% endblock %}
>
> detail.html
> {% extends "base.html" %}
> {% block body %}
> This is the detail
> {% endblock %}
>
> This will result in two pages -- an index and a detail page. Both have
> a header that reads "My Site", and a footer that says "thanks for
> coming"; however, the actual content in the body changes depending on
> the template.
>
> This sort of structure can then be layered -- so, for example, if
> there are many different types of detail page, you can have a "base
> detail" page that defines the blocks that exist on detail pages, and
> then specific detail pages that extend the base detail page.
>
> I hope this makes the design motivation of Django's template language
> a little more clear.
>
> Yours,
> Russ Magee %-)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to change the representation of newline?

2011-12-13 Thread Furbee
Yes, it is hard to determine the question. However, a stab in the dark, you
are trying to get a  tag to display a new line in a django template?
If so, any HTML that you want to render on the display needs to be passed
with the mark_safe() function. For example in views.py

from django.utils.safestring import mark_safe

def helloWorld(request):
message = "Hello   
    World!"
return render_to_response('hello_template.htm', {'message':
mark_safe(message)}, context_instance=RequestContext(request))


hello_template.htm:





Hello, World!
 

 
 {% if message %}
  {{ message }}
 {% endif %}
 


Produces a page like:
Hello
  World!

Without mark_safe(message) page just displays HTML not rendered in plain
text:
  Hello     
  World!

Hope that helps. If you are talking about manipulating characters, see
http://stackoverflow.com/questions/227459/ascii-value-of-a-character-in-python.
You can use ord() and chr() to switch carriage return/line feeds using the
ascii ordinal representation and back if you need to.

Furbee

2011/12/13 Tom Evans 

> 2011/12/13 Germán :
> > Has anybody solved this issue?
> >
> > On Dec 14 2006, 2:47 pm, "Aidas Bendoraitis"
> >  wrote:
> >> I ran out of ideas. :) Maybe somebody else has any thoughts regarding
> new lines?
> >>
> >> Good luck with Django!
> >> Aidas Bendoraitis [aka Archatas]
> >>
> >> On 12/14/06, zhongke chen  wrote:
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> > firefox shows utf-8
> >>
> >> > my firefox is 2.0
> >>
> >> > On 12/14/06, Aidas Bendoraitis  wrote:
> >> > > And what encoding is showed in the page info? ...when you right
> click
> >> > > somewhere in the page and choose "View Page Info" from the menu.
> Maybe
> >> > > just the default character encoding in your firefox settings is set
> >> > > wrongly?
> >>
> >> > > You can always override admin templates copying them into your
> >> > > custom_templates/admin directory.
> >>
> >> > > Regards,
> >> > > Aidas Bendoraitis
> >>
> >> > > On 12/14/06, zhongke chen  wrote:
> >> > > > It's not my html page, but the django admin page.
> >>
> >> > > > the head of admin page is like this:
> >>
> >> > > >  >> > > > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
> >> > > > http://www.w3.org/1999/xhtml"; lang="zh-cn"
> xml:lang="zh-cn" >
> >> > > > 
> >> > > > 站点管理员
> >> > > >  >> > > > href="/oj/adminmedia/css/dashboard.css" />
> >> > > > 
> >>
> >> > > > no encoding here, but lang = 'zh-cn'.
> >>
> >> > > > and all chinese characters in my pages and mysql are encoded in
> UTF-8.
> >> > > > Locale of my server is like this:
> >>
> >> > > > LANG=zh_CN.UTF-8
> >> > > > LANGUAGE=zh_CN:zh:en_US:en
> >> > > > LC_CTYPE="zh_CN.UTF-8"
> >> > > > LC_NUMERIC="zh_CN.UTF-8"
> >> > > > LC_TIME="zh_CN.UTF-8"
> >> > > > LC_COLLATE="zh_CN.UTF-8"
> >> > > > LC_MONETARY="zh_CN.UTF-8"
> >> > > > LC_MESSAGES="zh_CN.UTF-8"
> >> > > > LC_PAPER="zh_CN.UTF-8"
> >> > > > LC_NAME="zh_CN.UTF-8"
> >> > > > LC_ADDRESS="zh_CN.UTF-8"
> >> > > > LC_TELEPHONE="zh_CN.UTF-8"
> >> > > > LC_MEASUREMENT="zh_CN.UTF-8"
> >> > > > LC_IDENTIFICATION="zh_CN.UTF-8"
> >> > > > LC_ALL=
> >>
> >> > > > On 12/13/06, Aidas Bendoraitis 
> wrote:
> >> > > > > It might be that it treats new lines as \r\n when you are using
> some
> >> > > > > windows-* encoding for your html pages. Check the source code.
> I would
> >> > > > > rather use UTF-8 in any case.
> >>
> >> > > > > Regards
> >> > > > > Aidas Bendoraitis [aka Archatas]
> >>
> >> > > > --
> >> > > > Yours, Zhongke Chen 陈忠克
> >>
> >> > --
> >> > Yours, Zhongke Chen 陈忠克
> >>
> >> > 欢迎访问温州本地Linux论坛:http://groups.google.com/group/linux-wz
> >>
> >> > 请用czk19790...@gmail.com
> 与我联系,本人其它的邮箱已不再使用。如果要发word/excel/ppt文件给我,请先转成PDF格式。谢谢!PLEASE
> >> > contact me using czk19790...@gmail.com from now on. Other mail boxes
> >> > have been deprecated. If you want to attach word/excel/powerpoint
> >> > files for me, PLEASE convert them to pdf. Thanks a lot.
> >
>
> If there is a question in that mass of forwarded emails, I could not
> find it. The most important thing when getting help is to precisely
> and concisely state what your problem is. I'd start from there.
>
> Cheers
>
> Tom
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: 404 only in Chrome

2011-12-09 Thread Furbee
In urls.py:

Change:
(r'^portfolio/', include('project.urls.web')),

To:
(r'^portfolio/$', include('project.urls.web')),

The dollar sign makes it the end of the regular expression string. Without
it, /portfolio/ will match with /portfolio/funstuff,
/portfolio/?my_hax_rock, etc. See if that helps.

Furbee

On Fri, Dec 9, 2011 at 5:33 PM, neridaj  wrote:

> Hello,
>
> For some reason I'm getting a 404 in google chrome when I visit /
> portfolio/. The url entered is /portfolio/ but it returns as a 404 at /
> portfolio/undefined/ in the chrome developer tools window. I read a
> post about some issues with chrome handling errors and to resolve it
> by unchecking "Use a web service to help resolve navigation errors"
> but this didn't help with my problem. I'm not sure why undefined is
> being appended to the url, any ideas?
>
> urls.py:
>
> (r'^portfolio/', include('project.urls.web')),
>
> project/urls/web.py:
>
> urlpatterns = patterns('django.views.generic.list_detail',
>(r'^$', 'object_list', web_project_info_dict,
> 'project_web_archive_index'),
>(r'^(?P[-\w]+)/$', 'object_detail', web_project_info_dict),
> )
>
> If it was a real 404 why isn't my error page displayed i.e., when I
> visit /portfolio/non-existent-slug, I get the proper 404 page.
>
> >>> django.VERSION
> (1, 2, 0, 'alpha', 0)
>
> Thanks for any help!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Can't figure out this Object Model error...

2011-12-05 Thread Furbee
That is what I sort of assumed. You created the table with syncdb, changed
the models.py for it and ran syncdb, which does nothing if the table
already exists.


On Mon, Dec 5, 2011 at 5:04 PM, Reinout van Rees wrote:

> On 06-12-11 01:24, Marc Edwards wrote:
>
>> DatabaseError at/admin/bookmarks/eda_**appcatalog/
>>
>> no such column: bookmarks_eda_appcatalog.eda_**app_id
>>
>
> The "eda_app_id" colum is what Django uses to store the foreign key. You
> probably added the foreign key after creating the EDA_AppCatalog class.
> Your syncdb after creating EDA_AppCatalog created the table.
>
> After adding the foreign key, the table already exists, so syncdb doesn't
> do anything. For adding columns to existing tables, syncdb is useless.
>
> - Either create the column by hand.
>
> - Delete the table and re-create it with syncdb (it will now contain the
> foreign key column).
>
> - Use south for database migrations.
>
>
>
>
> Reinout
>
> --
> Reinout van Reeshttp://reinout.vanrees.org/
> rein...@vanrees.org 
> http://www.nelen-schuurmans.**nl/
> "If you're not sure what to do, make something. -- Paul Graham"
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@**
> googlegroups.com .
> For more options, visit this group at http://groups.google.com/**
> group/django-users?hl=en
> .
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Can't figure out this Object Model error...

2011-12-05 Thread Furbee
Don't mean to sound remedial, but have you verified that the table
bookmarks_eda_appcatalog exists and that it has a column named eda_app_id?
Did you use manage.py syncdb to create the tables?

Furbee

On Mon, Dec 5, 2011 at 4:24 PM, Marc Edwards  wrote:

> I am receiving the following error from the Django debugger when
> trying to access my EDA_AppCatalog object.  My class definition is
> listed below.  I have similar defined objects that are working with no
> problem, but I can't seem to clear this error message up.
>
> Thanks, Marc
>
> DatabaseError at /admin/bookmarks/eda_appcatalog/
>
> no such column: bookmarks_eda_appcatalog.eda_app_id
>
> Request Method: GET
> Request URL:http://127.0.0.1:8000/admin/bookmarks/eda_appcatalog/
> Django Version: 1.3.1
> Exception Type: DatabaseError
> Exception Value:
>
> no such column: bookmarks_eda_appcatalog.eda_app_id
>
> Exception Location: /usr/local/lib/python2.7/dist-packages/django/db/
> backends/sqlite3/base.py in execute, line 234
> Python Executable:  /usr/bin/python2.7
> Python Version: 2.7.2
> Python Path:
>
> ['/home/jmarcedwards/KeplerDevelopment/KeplerEclipseWorkspace_1/
> JME_DjangoTest_3/JME_DjangoTest_3',
>
> ---
> class EDA_AppCatalog(models.Model):
>
>eda_app = models.ForeignKey(EDA_App)
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Problem with Django and AJAX: Empty responsetext

2011-11-21 Thread Furbee
Disclaimer: I don't know if this is at all related, but I had an issue with
an AJAX object I created outside a function. Can you try this and let me
know if it works?

Change this:
var searchReq = getXmlHttpRequestObject();
to this:
searchReq = getXmlHttpRequestObject();

and move it into searchSuggest(), like:
function searchSuggest() {
searchReq = getXmlHttpRequestObject();
.
.
.
}

I can't explain this, but it tripped me up, because creating the AJAX
object globally, outside a function, didn't seem to work. I read an
explanation that made some sense, although it seemed like a bug, but it has
been too long and I can't remember exactly what the problem was. Keep me
posted.

Furbee

On Mon, Nov 21, 2011 at 1:10 PM, Schmidtchen Schleicher <
spiolli...@googlemail.com> wrote:

> I'm trying to do a simple google-suggest like thing with django and ajax.
> I wrote a view for creating the response and try to use it via an
> XMLHttpRequest.
> Here's my view:
>
>
> def category_suggest(request):
>> if request.method == "GET":
>> return_categories = ''
>> received_str = request.GET['str']
>> found_categories =
>> Category.objects.filter(name__istartswith=received_str) #i stands for
>> incasesensitive
>> if found_categories:
>> for cat in found_categories:
>> return_categories = return_categories + cat.name + "\n"
>>
>> print "returned str:"
>> print return_categories
>> return HttpResponse(str(return_categories), mimetype='text/plain')
>> else:
>> return HttpResponse('')
>>
>
> This view appears to work, because if I open the corresponding url in a
> browser the data is displayed.
> But it doesn't work via ajax: this is the javascript code:
>
> //Gets the browser specific XmlHttpRequest Object
>> function getXmlHttpRequestObject() {
>> console.debug("GettingXMLHTTP");
>> if (window.XMLHttpRequest) {
>> return new XMLHttpRequest();
>> } else if(window.ActiveXObject) {
>> return new ActiveXObject("Microsoft.XMLHTTP");
>> } else {
>> alert("Your Browser Sucks!\nIt's about time to upgrade don't you
>> think?");
>> }
>> }
>>
>> //Our XmlHttpRequest object to get the auto suggest
>> var searchReq = getXmlHttpRequestObject();
>>
>> //Called from keyup on the search textbox.
>> //Starts the AJAX request.
>> function searchSuggest() {
>> if (searchReq.readyState == 4 || searchReq.readyState == 0) {
>> console.debug("start suggest...");
>> var str = escape(document.getElementById('txtSearch').value);
>> searchReq.onreadystatechange = handleSearchSuggest;
>> var myDate = new Date();
>> var myTime = myDate.getTime();
>> searchReq.open("GET", '
>> http://127.0.0.1:8000/kalender/ajax/category_suggest/?str=' + str +
>> "&time=" + myTime, true);
>> console.debug("sending");
>> searchReq.send(null);
>> }
>> }
>>
>> //Called when the AJAX response is returned.
>> function handleSearchSuggest() {
>> console.debug("Handling suggest");
>> if (searchReq.readyState == 4) {
>> console.debug("ReadyState is 4");
>> var ss = document.getElementById('search_suggest')
>> ss.innerHTML = '';
>> var rstr = searchReq.responseText.split("\n");
>> console.debug("Response:"+JSON.stringify(searchReq));
>> for(i=0; i < rstr.length - 1; i++) {
>> //Build our element string.  This is cleaner using the DOM,
>> but
>> //IE doesn't support dynamically added attributes.
>> var suggest = '> suggest += 'onclick="javascript:setSearch(this.innerHTML);" ';
>> suggest += 'class="suggest_link">' + rstr[i] + '';
>> ss.innerHTML += suggest;
>> }
>> }
>> }
>>
>> //Click function
>> function setSearch(value) {
>> document.getElementById('txtSearch').value = value;
>> document.getElementById('search_suggest').innerHTML = '';
>> }
>>
>
> Every function is getting entered and firebug shows there's is a request
> sendet to the django view but the respon

Re: syncdb not finding and syncing my MySQL database

2011-11-21 Thread Furbee
Yes, please offer more details. One thing I noticed off the bat, though,
was that you said you are running "python manage.py syncdb" from the
directory where your models.py is. The manage.py file is at the root of
your project, not in the apps folder(s) where models.py is.

Furbee

On Mon, Nov 21, 2011 at 10:13 AM, Anoop Thomas Mathew wrote:

> Hi,
>
> "I am getting an error"
> This is not a proper way to ask question. Please post
> your trace-back somewhere and send the link to the group or at least
> specify what error is it, so that, we could help you.
> Thanks,
> Anoop
>
>
> atm
> ___
> Life is short, Live it hard.
>
>
>
>
>
> On 21 November 2011 23:31, BillB1951  wrote:
>
>> Problem when I try to run "python manage.py" I get an error.  It
>> appears that my MySQL database cannot be found, but syncdb know it's
>> name, which I assume it got from my settings.py file.
>>
>> Any suggests will be very much appreciated.   Thanks
>>
>> Bill
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: ImportError: No module named django

2011-11-18 Thread Furbee
You can get to the python interactive interpreter by typing "python" into a
Dos shell, as long as the python executable is in your system path. The
IDLE command line should work, also. In the Python folder there should be a
site-packages folder which contains a folder named django. The "import
django" command is attempting to import from there by default. So, if that
is failing, the django site package must not be installed properly. When
you download the Django package as a zip file, extract it to a location.
>From that location there is a setup.py file. From a shell go to that
location and enter "python setup.py install". This should install the
Django framework into the Python site-packages folder, and the "import
django" should work from a python shell.

Cheers,

Furbee

On Fri, Nov 18, 2011 at 12:14 PM, Jenny  wrote:

> I am as newbie as for two hours ago I installed Python 2.7.2 and an
> hour ago installed BitNami DjangoStack 1.3.1 on my Windows 7 machine.
> I am trying to start with a tutorial on the Djangos website which
> says:
> "You can tell Django is installed by running the Python interactive
> interpreter and typing import django"
>
> I assume that the "Python interactive interpreter" is IDLE (Python
> GUI). When i run it and on the command line I write "import django", I
> get a message as follwoing:
> >>> import django
> Traceback (most recent call last):
>  File "", line 1, in 
>import django
> ImportError: No module named django
>
> Would you please give me help some advice what to do here? Many thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Relation not found error while dealing with foreign keys and forms

2011-11-07 Thread Furbee
I guess the form object is not holding the nics_group object, in this case,
you could send the group information (all groups in one array or other
object, and the selected group in another variable) back to the template as
a separate object. However, the suggested paradigm is using Database
Routers. With the database routers, you can force the instances of the
NICSGroupType and Staff to use the gold database. More details here:
https://docs.djangoproject.com/en/1.3/topics/db/multi-db/#automatic-database-routing.
I submitted a bug ticket over the weekend (
https://code.djangoproject.com/ticket/17167), but it was closed by a
contributor who seemed to misunderstand the situation. The issue is
somewhere in the ModelForm class, since everything works UNTIL you use the
staff object as an instance to the ModelForm StaffForm object. The
ModelForm class is looking to the default database for referential objects.
There are not arguments I can find to forcefully tell ModelForm to use a
non-default database. So, it may be that Database Routers are the only way
you can get ModelForm to look for NICSGroupType in the database 'gold.'

Furbee

On Sun, Nov 6, 2011 at 3:04 PM, Tabitha Samuel wrote:

> Hey thanks a bunch for the workaround. Maybe I am doing something
> wrong, but this is what I'm getting when I implement it and it really
> seems weird..
>
> in my view I have:
>staff_person =
> Staff.objects.using('gold').get(username=current_staff)
>form = StaffForm(instance = staff_person)
>group
>
> =NICSGroupType.objects.using('gold').get(n_group_number=staff_person.nics_group.n_group_number)
>form.nics_group = group
>print form.nics_group
>print form
>
> The first print gives me "3" which is correct. The print form on the
> other hand gives me the same:
> Exception Type: DatabaseError at /staff/staffinfo
> Exception Value: relation "n_nics_groups" does not exist
>
> If I comment out that print and render the template, I get pretty much
> the same error:
> Exception Type: TemplateSyntaxError at /staff/staffinfo
> Exception Value: Caught DatabaseError while rendering: relation
> "n_nics_groups" does not exist
> and the problem line in the template is: NICS Group:  td>{{form.nics_group}}
>
> So the question is how can it print the group number when I do a print
> form.group_number but exception out when I do a print form?
>
> Tabitha
>
> On Nov 5, 11:26 am, Furbee  wrote:
> > As a workaround to this bug, you could get the group separately, and
> attach
> > all of the group fields to the staff form manually until a fix is
> > implemented. Something like (hasn't been tested, you may need to assign
> > each NICSGroupType field to a form field):
> >
> > staff = Staff.objects.using('gold').get(username=current_staff)
> > form = StaffForm(instance = staff)
> > group =
> >
> NICSGroupType.objects.using('gold').get(n_group_number=staff.nics_group.n_group_number)
> >
> > form.nics_group = group # this may attach all fields, but most likely
> > you'll have to attach them manually, since they would just be a goup, not
> > FormFields.
> >
> > Hopefully that will get you through this jam, until a fix is created. I
> > haven't written any patches before, but I will see if I can figure it
> out,
> > time permitting.
> >
> > Thanks,
> >
> > Furbee
> >
> >
> >
> >
> >
> >
> >
> > On Fri, Nov 4, 2011 at 3:36 PM, Furbee  wrote:
> > > No worries. Wow, I've got some interesting results. I am pretty sure
> the
> > > ModelForm class has a bug in it that it is not looking at the secondary
> > > database with the using() method. It is a bug in the foreign reference
> > > fields only, though.
> >
> > > I set up tables in my default database, and in an extra database named
> > > staff, which is set up in settings.py.
> >
> > > In default DB:
> > > n_test_staff
> > > username;nics_group
> > > "tsamuel";1
> >
> > > n_nics_groups
> > > n_group_number;n_group_name
> > > 1;"Group1"
> > > 2;"Group2"
> >
> > > In staff DB:
> > > n_test_staff
> > > username;nics_group
> > > "tsamuel";2 (Notice tsamuel in group 2 in this DB)
> >
> > > n_nics_groups
> > > n_group_number;n_group_name
> > > 1;"Staff1"
> > > 2;"Staff2"
> >
> > > In the models, wrote __unicode__(self): method to show the groups.
> >
> > > Here's something strange:

Re: How do I define a default (override-able) primary key field on an abstract model?

2011-11-05 Thread Furbee
I can't speak to the reference field being used as a primary key, but the
initial error is that you have multiple primary keys on the single model B.
If it 'is-a' class Base, it inherits id as a primary key, and also defines
a and a primary key. You cannot have multiple primary key fieds, hence
"table B has more than one primary key."

Furbeenator

On Sat, Nov 5, 2011 at 3:48 PM, Kurtis Mullins wrote:

> I don't think the problem is overriding the Primary Key. I could be wrong,
> but I think the actual problem here is that you can not use OneToOneFields,
> ManyToManyFields, or ForeignKeys as primary keys. I'm not sure how it would
> work on a database level. Like I said, I could be wrong -- but that's my
> initial hunch. Try overriding it with something else like an IntegerField
> and see if you still get an error.
>
>
> On Sat, Nov 5, 2011 at 6:19 PM, g  wrote:
>
>> How do I define a custom primary key field on Base that can be
>> overridden by B without an error?
>>
>> class Base(Model):
>>class Meta:
>>abstract = True
>>id = SomeAwesomeIDField(primary_key=True)
>>other_common_field = AwesomeField()
>>
>> class A(Base):
>>pass
>>
>> class B(Base):
>>a = OneToOneField(A,primary_key=True)
>>
>>
>>
>> django.db.utils.DatabaseError: table "..." has more than one primary
>> key
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: [Django] #17167: ModelForm model=class not honoring reference fields with secondary database

2011-11-05 Thread Furbee
No, that is incorrect. The Foreign key does not cross database boundaries.
The employee table is in the secondary database, and the department table
is also in the secondary database. The foreign key from from the employee
table to the department table, both in the same secondary database.

Furbeenator

On Sat, Nov 5, 2011 at 10:26 AM, Django  wrote:

> #17167: ModelForm model=class not honoring reference fields with secondary
> database
> -+-
> Reporter:  furbeenator@…|Owner:  nobody
>  Type:  Bug  |   Status:  closed
>Component:  Forms|  Version:  1.3
> Severity:  Normal   |   Resolution:  invalid
>  Keywords:  ModelForm, using(),  | Triage Stage:
>  foreign key, reference field   |  Unreviewed
>Has patch:  0|  Needs documentation:  0
>  Needs tests:  0|  Patch needs improvement:  0
> Easy pickings:  0|UI/UX:  0
> -+-
> Changes (by kmtracey):
>
>  * status:  new => closed
>  * resolution:   => invalid
>
>
> Comment:
>
>  Near as I can tell you are trying to have !ForeignKeys that cross database
>  boundaries. This is not supported by Django's multiple database support,
>  see: https://docs.djangoproject.com/en/1.3/topics/db/multi-db/#cross-
>  database-relations
>
> --
> Ticket URL: 
> Django 
> The Web framework for perfectionists with deadlines.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Relation not found error while dealing with foreign keys and forms

2011-11-05 Thread Furbee
As a workaround to this bug, you could get the group separately, and attach
all of the group fields to the staff form manually until a fix is
implemented. Something like (hasn't been tested, you may need to assign
each NICSGroupType field to a form field):

staff = Staff.objects.using('gold').get(username=current_staff)
form = StaffForm(instance = staff)
group =
NICSGroupType.objects.using('gold').get(n_group_number=staff.nics_group.n_group_number)

form.nics_group = group # this may attach all fields, but most likely
you'll have to attach them manually, since they would just be a goup, not
FormFields.

Hopefully that will get you through this jam, until a fix is created. I
haven't written any patches before, but I will see if I can figure it out,
time permitting.

Thanks,

Furbee


On Fri, Nov 4, 2011 at 3:36 PM, Furbee  wrote:

> No worries. Wow, I've got some interesting results. I am pretty sure the
> ModelForm class has a bug in it that it is not looking at the secondary
> database with the using() method. It is a bug in the foreign reference
> fields only, though.
>
> I set up tables in my default database, and in an extra database named
> staff, which is set up in settings.py.
>
> In default DB:
> n_test_staff
> username;nics_group
> "tsamuel";1
>
> n_nics_groups
> n_group_number;n_group_name
> 1;"Group1"
> 2;"Group2"
>
> In staff DB:
> n_test_staff
> username;nics_group
> "tsamuel";2 (Notice tsamuel in group 2 in this DB)
>
> n_nics_groups
> n_group_number;n_group_name
> 1;"Staff1"
> 2;"Staff2"
>
> In the models, wrote __unicode__(self): method to show the groups.
>
>
> Here's something strange:
> >>> from models import Staff, NICSGroupType
> >>> from django.forms import ModelForm
> >>> class StaffForm(ModelForm):
> ... class Meta:
> ... model = Staff
> ...
> >>> staff = Staff.objects.using('staff').get(username='tsamuel')
> >>> print staff
> tsamuel 
> >>> form = StaffForm(instance=staff)
> >>> print form
> Username: id="id_username" type="text" name="username" value="tsamuel" maxlength="50"
> />
> Nics group: name="nics_group" id="id_nics_group">
> -
> 2: Group2
> 1: Group1
> 
>
> Notice this ModelForm is getting the Staff data from the 'staff' database,
> but is getting the reference n_nics_groups data from the default database's
> n_nics_groups table. Remember in staff tsamuel was part of group 2, which
> is the selected option, but the label is Group2 instead of Staff2, which is
> the value in n_nics_groups table in the 'staff' database.
>
>
> Then I tried deleting the default database n_test_staff table to verify:
> >>> from models import Staff, NICSGroupType
> >>> from django.forms import *
> >>> class StaffForm(ModelForm):
> ... class Meta:
> ... model = Staff
> ...
> >>> staff = Staff.objects.using('staff').get(username='tsamuel')
> >>> form = StaffForm(instance=staff)
> >>> print form
> Username: id="id_username" type="text" name="username" value="tsamuel" maxlength="50"
> />
> Nics group: name="nics_group" id="id_nics_group">
> -
> 2: Group2
> 1: Group1
> 
>
>
>
> Now, if I delete the default database's n_nics_groups table also, so it
> should all be using the 'staff' database, the only place n_test_staff and
> n_nics_groups exist now.
> >>> from models import Staff, NICSGroupType
> >>> from django.forms import *
> >>> class StaffForm(ModelForm):
> ... class Meta:
> ... model = Staff
> ...
> >>> staff = Staff.objects.using('staff').get(username='tsamuel')
> >>> print staff
> tsamuel 
> >>> form = StaffForm(instance=staff)
> >>> print form
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python2.5/site-packages/django/utils/encoding.py", line
> 27, in __str__
> return self.__unicode__().encode('utf-8')
>   File "/usr/lib/python2.5/site-packages/django/forms/forms.py", line 95,
> in __unicode__
> return self.as_table()
>   File "/usr/lib/python2.5/site-packages/django/forms/forms.py", line 217,
> in as_table
> errors_on_separate_row = False)
>   File "/usr/lib/python2.5/site-packages/django/forms/forms

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Furbee
No worries. Wow, I've got some interesting results. I am pretty sure the
ModelForm class has a bug in it that it is not looking at the secondary
database with the using() method. It is a bug in the foreign reference
fields only, though.

I set up tables in my default database, and in an extra database named
staff, which is set up in settings.py.

In default DB:
n_test_staff
username;nics_group
"tsamuel";1

n_nics_groups
n_group_number;n_group_name
1;"Group1"
2;"Group2"

In staff DB:
n_test_staff
username;nics_group
"tsamuel";2 (Notice tsamuel in group 2 in this DB)

n_nics_groups
n_group_number;n_group_name
1;"Staff1"
2;"Staff2"

In the models, wrote __unicode__(self): method to show the groups.


Here's something strange:
>>> from models import Staff, NICSGroupType
>>> from django.forms import ModelForm
>>> class StaffForm(ModelForm):
... class Meta:
... model = Staff
...
>>> staff = Staff.objects.using('staff').get(username='tsamuel')
>>> print staff
tsamuel 
>>> form = StaffForm(instance=staff)
>>> print form
Username:
Nics group:
-
2: Group2
1: Group1


Notice this ModelForm is getting the Staff data from the 'staff' database,
but is getting the reference n_nics_groups data from the default database's
n_nics_groups table. Remember in staff tsamuel was part of group 2, which
is the selected option, but the label is Group2 instead of Staff2, which is
the value in n_nics_groups table in the 'staff' database.


Then I tried deleting the default database n_test_staff table to verify:
>>> from models import Staff, NICSGroupType
>>> from django.forms import *
>>> class StaffForm(ModelForm):
... class Meta:
... model = Staff
...
>>> staff = Staff.objects.using('staff').get(username='tsamuel')
>>> form = StaffForm(instance=staff)
>>> print form
Username:
Nics group:
-
2: Group2
1: Group1




Now, if I delete the default database's n_nics_groups table also, so it
should all be using the 'staff' database, the only place n_test_staff and
n_nics_groups exist now.
>>> from models import Staff, NICSGroupType
>>> from django.forms import *
>>> class StaffForm(ModelForm):
... class Meta:
... model = Staff
...
>>> staff = Staff.objects.using('staff').get(username='tsamuel')
>>> print staff
tsamuel 
>>> form = StaffForm(instance=staff)
>>> print form
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.5/site-packages/django/utils/encoding.py", line
27, in __str__
return self.__unicode__().encode('utf-8')
  File "/usr/lib/python2.5/site-packages/django/forms/forms.py", line 95,
in __unicode__
return self.as_table()
  File "/usr/lib/python2.5/site-packages/django/forms/forms.py", line 217,
in as_table
errors_on_separate_row = False)
  File "/usr/lib/python2.5/site-packages/django/forms/forms.py", line 180,
in _html_output
'field': unicode(bf),
  File "/usr/lib/python2.5/site-packages/django/forms/forms.py", line 408,
in __unicode__
return self.as_widget()
  File "/usr/lib/python2.5/site-packages/django/forms/forms.py", line 439,
in as_widget
return widget.render(name, self.value(), attrs=attrs)
  File "/usr/lib/python2.5/site-packages/django/forms/widgets.py", line
516, in render
options = self.render_options(choices, [value])
  File "/usr/lib/python2.5/site-packages/django/forms/widgets.py", line
533, in render_options
for option_value, option_label in chain(self.choices, choices):
  File "/usr/lib/python2.5/site-packages/django/forms/models.py", line 882,
in __iter__
for obj in self.queryset.all():
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line
107, in _result_iter
self._fill_cache()
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line
772, in _fill_cache
self._result_cache.append(self._iter.next())
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line
273, in iterator
for row in compiler.results_iter():
  File "/usr/lib/python2.5/site-packages/django/db/models/sql/compiler.py",
line 680, in results_iter
for rows in self.execute_sql(MULTI):
  File "/usr/lib/python2.5/site-packages/django/db/models/sql/compiler.py",
line 735, in execute_sql
cursor.execute(sql, params)
  File
"/usr/lib/python2.5/site-packages/django/db/backends/postgresql_psycopg2/base.py",
line 44, in execute
return self.cursor.execute(query, args)
DatabaseError: relation "n_nics_groups" does not exist


This

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Furbee
I guess the ModelForm must require the Meta class, sorry about that. This
is really strange behavior, but it looks like everything you've got is
correct.

Running syncdb will only create new databases/tables, it does not ALTER any
existing tables or modify any of the data. However, if you have other
models that don't have corresponding tables created, syncdb would create
those.

Furbee

On Fri, Nov 4, 2011 at 11:46 AM, Tabitha Samuel wrote:

> Yep, n_nics_groups and n_test_staff exist in the same 'gold'
> database.
>
> So when I tried:
> form = StaffForm(instance = Staff.objects.using('gold').raw("SELECT
> s.*, g.n_group_name FROM n_test_staff s LEFT JOIN n_nics_groups g
> ON(g.n_group_number = s.nics_group) WHERE s.username = 'tsamuel')"))
>I got the error:
> 'QuerySet' object has no attribute 'raw'
>
> and when I tried:
> form = StaffForm(instance = Staff.objects.raw("SELECT s.*,
> g.n_group_name FROM n_test_staff s LEFT JOIN n_nics_groups g
> ON(g.n_group_number = s.nics_group) WHERE s.username =
> 'tsamuel')")).using('gold')
> 'RawQuerySet' object has no attribute '_meta'
>
> So here is one thing, both tables (n_test_staff and n_nics_groups)
> were pre-existing, meaning I have not created them using syncdb from
> the models. They're been used by other applications within my group.
> I've just created the models that would correspond to these tables, I
> have not run syncdb on the database. I am a little hesitant to do so,
> since I don't want to change the db values and mess up other
> applications.
>
> Tabitha
>
> On Nov 4, 2:28 pm, Furbee  wrote:
> > That is very strange... I recreated this on my development system and it
> > worked fine. I looked for Django bugs, but haven't found any related to
> > this issue. To be clear, the table n_nics_groups definitely exists in the
> > same database as n_test_staff, right? It does in mine because I used
> python
> > manage.py syncdb to create them from the models. If so, maybe we should
> try
> > to create a raw() query to see if the system has a bug creating the
> query.
> > This should be similar:
> >
> > form = StaffForm(instance = Staff.objects.raw("SELECT s.*, g.n_group_name
> > FROM n_test_staff s LEFT JOIN n_nics_groups g ON(g.n_group_number =
> > s.nics_group) WHERE s.username = 'tsamuel'))
> >
> > If that throws an error, we may have a problem in the DB layer.
> >
> > Thanks,
> >
> > Furbee
> >
> > On Fri, Nov 4, 2011 at 10:29 AM, Tabitha Samuel <
> tabitha.sam...@gmail.com>wrote:
> >
> >
> >
> >
> >
> >
> >
> > > The error that I'm getting is on the second form instantiation, that
> > > is on the line:
> >
> > > form = StaffForm(instance = Staff.objects.using('gold').get(username =
> > > current_staff)
> > > where current_staff='tsamuel' for instance
> >
> > > This is the traceback of the error that I get when I do a print form
> > > right after getting the form:
> > > Environment:
> >
> > > Request Method: GET
> > > Request URL:http://watermelon.nics.utk.edu:8004/staff/staffinfo
> >
> > > Django Version: 1.3.1
> > > Python Version: 2.6.2
> > > Installed Applications:
> > > ['django.contrib.auth',
> > >  'django.contrib.contenttypes',
> > >  'django.contrib.sessions',
> > >  'django.contrib.sites',
> > >  'gibbs.quartermaster',
> > >  'gibbs.userportal',
> > >  'gibbs.reports',
> > >  'gibbs.events',
> > >  'gibbs.job_stats',
> > >  'gibbs.simulator',
> > >  'gibbs.staff']
> > > Installed Middleware:
> > > ('django.contrib.csrf.middleware.CsrfViewMiddleware',
> > >  'django.middleware.common.CommonMiddleware',
> > >  'django.contrib.csrf.middleware.CsrfResponseMiddleware',
> > >  'django.contrib.sessions.middleware.SessionMiddleware',
> > >  'django.contrib.auth.middleware.AuthenticationMiddleware')
> >
> > > Traceback:
> > > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > > core/handlers/base.py" in get_response
> > >  111. response = callback(request,
> > > *callback_args, **callback_kwargs)
> > > File "/nics/a/applications/gibbs/python/site-pac

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Furbee
That is very strange... I recreated this on my development system and it
worked fine. I looked for Django bugs, but haven't found any related to
this issue. To be clear, the table n_nics_groups definitely exists in the
same database as n_test_staff, right? It does in mine because I used python
manage.py syncdb to create them from the models. If so, maybe we should try
to create a raw() query to see if the system has a bug creating the query.
This should be similar:

form = StaffForm(instance = Staff.objects.raw("SELECT s.*, g.n_group_name
FROM n_test_staff s LEFT JOIN n_nics_groups g ON(g.n_group_number =
s.nics_group) WHERE s.username = 'tsamuel'))

If that throws an error, we may have a problem in the DB layer.

Thanks,

Furbee

On Fri, Nov 4, 2011 at 10:29 AM, Tabitha Samuel wrote:

> The error that I'm getting is on the second form instantiation, that
> is on the line:
>
> form = StaffForm(instance = Staff.objects.using('gold').get(username =
> current_staff)
> where current_staff='tsamuel' for instance
>
> This is the traceback of the error that I get when I do a print form
> right after getting the form:
> Environment:
>
>
> Request Method: GET
> Request URL: http://watermelon.nics.utk.edu:8004/staff/staffinfo
>
> Django Version: 1.3.1
> Python Version: 2.6.2
> Installed Applications:
> ['django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.sites',
>  'gibbs.quartermaster',
>  'gibbs.userportal',
>  'gibbs.reports',
>  'gibbs.events',
>  'gibbs.job_stats',
>  'gibbs.simulator',
>  'gibbs.staff']
> Installed Middleware:
> ('django.contrib.csrf.middleware.CsrfViewMiddleware',
>  'django.middleware.common.CommonMiddleware',
>  'django.contrib.csrf.middleware.CsrfResponseMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
>
> Traceback:
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> core/handlers/base.py" in get_response
>  111. response = callback(request,
> *callback_args, **callback_kwargs)
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> contrib/auth/decorators.py" in _wrapped_view
>  23. return view_func(request, *args, **kwargs)
> File "/nics/a/home/tsamuel/tssandbox/gibbs/utils/decorators.py" in
> decorate
>  11. return view_func(request, *args, **kws)
> File "/nics/a/home/tsamuel/tssandbox/gibbs/../gibbs/staff/views.py" in
> staff_info
>  159. print form
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> utils/encoding.py" in __str__
>  27. return self.__unicode__().encode('utf-8')
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> forms/forms.py" in __unicode__
>  95. return self.as_table()
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> forms/forms.py" in as_table
>  217. errors_on_separate_row = False)
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> forms/forms.py" in _html_output
>  180. 'field': unicode(bf),
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> forms/forms.py" in __unicode__
>  408. return self.as_widget()
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> forms/forms.py" in as_widget
>  439. return widget.render(name, self.value(), attrs=attrs)
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> forms/widgets.py" in render
>  516. options = self.render_options(choices, [value])
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> forms/widgets.py" in render_options
>  533. for option_value, option_label in chain(self.choices,
> choices):
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> forms/models.py" in __iter__
>  882. for obj in self.queryset.all():
> File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
> models/query.py" in _result_iter
>  107. self._fill_cache()
> File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
> models/query.py" in _fill_cache
>  772.
> self._result_cache.append(self._iter.next())
> File "/nics/a/applications/gibbs/python/site-package

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Furbee
Oh no, that would not be a good thing to share! :-) That's a bummer that
the upgrade broke things.

So, the error is being raised on this line?
staff_form = StaffForm(request.POST, instance=staffinstance).using('gold')

Furbee

On Fri, Nov 4, 2011 at 8:02 AM, Tabitha Samuel wrote:

> So this is how I'm creating the staff form:
>
> def staff_info(request, *args, **kws):
>class StaffForm(forms.ModelForm):
>class Meta:
>  model= Staff
>  
>  
>  
>  if request.method == 'POST' and request.POST['event'] ==
> 'choosestaff':
> current_staff =
> request.POST.get('selectstaff')
> elif request.method == 'POST' and request.POST['event'] ==
> 'editstaff':
> #print
> request
> current_staff =
> request.POST.get('username')
> errors =
> validate_staff(request)
> if errors is not None and len(errors) ==
> 0:
> print
> request.POST
> staffinstance = Staff.objects.using('gold').get(username =
> current_staff)
> #new_form =
> StaffForm(instance=staffinstance)
> #print
> new_form
> staff_form = StaffForm(request.POST,
> instance=staffinstance).using('gold')
> staff_form.last_modification_time =
> datetime.now()
> staff_form.supervisor =
> staffinstance.supervisor
> staff_form.start_date =
> staffinstance.start_date
>staff_form.creation_time =
> staffinstance.creation_time
>staff_form.termination_date =
> staffinstance.termination_date
>   staff_form.using('gold').save()
>
> else:
>current_staff =
> request.user.username
>tg_info,staff, nics_info =
> get_tg_info(current_staff)
>
>groups =
> NICSGroupType.objects.using('gold').all()
> form = StaffForm(instance =
> Staff.objects.using('gold').select_related().get(username =
> current_staff))
>print
> form
>return render_to_response('staff/staffinfo.html',{'form':form,
> 'tginfo':tg_info, 'nicsinfo': nics_info, 'staff':staff,
> 'is_admin':is_admin, 'errors':errors},context_instance =
> RequestContext(request))
>
>
> Funny thing is that this worked perfectly in version 1.1a of django.
> All trouble started when I switched to 1.3. I was using extDbManager
> to create the gold connection in the 1.1 version since 'gold' is a non-
> default db (used only for this model) and 1.1 only had in built
> support for a single db.
>
> And yes, I do have a page for the view. Problem is that it is passcode
> protected and I don't think I'm at liberty to give you access to it. :
> (
>
> Tabitha
> On Nov 4, 10:44 am, Mark Furbee  wrote:
> > Good Morning Tabitha.
> >
> > Actually, do you have a model for StaffForm? That is the object being
> > instantiated and then causing the error. If there is no nics group
> > reference field in the StaffForm object, it may raise this error. Also,
> do
> > you have this running in a view/template? Do you have a real page that
> > you've tried this on, or have you just tried it in the shell?
> >
> > Thanks,
> >
> > Furbee
> >
> > On Fri, Nov 4, 2011 at 7:02 AM, Tabitha Samuel  >wrote:
> >
> >
> >
> >
> >
> >
> >
> > > Here is staff/models.py
> >
> > > from django.db import models
> >
> > > class NICSGroupType(models.Model):
> > >n_group_number = models.IntegerField(primary_key = True)
> > >n_group_name = models.CharField(max_length = 512)
> > > def __str__(self):
> > >return self.n_group_name
> > > class Meta:
> > >db_table = "n_nics_groups"
> >
> > > class StaffpageAdmin(models.Model):
> > >n_id= models.IntegerField(primary_key =
> > > True)
> > >n_username  = models.CharField(max_length = 50)
> > >class Meta:
> > >db_table = 'n_staffpage_admin'
> >
> > > class Staff(models.Model):
> > >username= models.CharField(primary_key = True,
> > > max_length = 50)
> > >home_phone  = models.CharField(max_length = 12,
> > > null=True)
> > >cell_phone  = models.CharField(max_length = 12,
> > > null = True)
> > >home_address= models.CharField(max_length = 1024,
> > > null = True)
> > >home_city

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Mark Furbee
Good Morning Tabitha.

Actually, do you have a model for StaffForm? That is the object being
instantiated and then causing the error. If there is no nics group
reference field in the StaffForm object, it may raise this error. Also, do
you have this running in a view/template? Do you have a real page that
you've tried this on, or have you just tried it in the shell?

Thanks,

Furbee

On Fri, Nov 4, 2011 at 7:02 AM, Tabitha Samuel wrote:

> Here is staff/models.py
>
> from django.db import models
>
> class NICSGroupType(models.Model):
>n_group_number = models.IntegerField(primary_key = True)
>n_group_name = models.CharField(max_length = 512)
> def __str__(self):
>return self.n_group_name
> class Meta:
>db_table = "n_nics_groups"
>
> class StaffpageAdmin(models.Model):
>n_id= models.IntegerField(primary_key =
> True)
>n_username  = models.CharField(max_length = 50)
>class Meta:
>db_table = 'n_staffpage_admin'
>
> class Staff(models.Model):
>username= models.CharField(primary_key = True,
> max_length = 50)
>home_phone  = models.CharField(max_length = 12,
> null=True)
>cell_phone  = models.CharField(max_length = 12,
> null = True)
>home_address= models.CharField(max_length = 1024,
> null = True)
>home_city   = models.CharField(max_length = 64,
> null = True)
>home_state  = models.CharField(max_length = 32,
> null = True)
>home_zip= models.CharField(max_length = 10,
> null = True)
>emergency_name  = models.CharField(max_length =64,
> null = True)
>emergency_phone = models.CharField(max_length = 12,
> null = True)
>nics_group  = models.ForeignKey(NICSGroupType,
> to_field="n_group_number",db_column="nics_group",
> null=True,blank=True)
>room_number = models.CharField(max_length = 32,
> null = True)
>title   = models.CharField(max_length = 64)
>supervisor  = models.CharField(max_length = 25,
> null = True, blank = True)
>url = models.CharField(max_length =
> 256,null = True, blank = True)
>im  = models.CharField(max_length = 32,
> null = True, blank=True)
>last_modification_time  = models.IntegerField()
>start_date  = models.IntegerField()
>creation_time   = models.IntegerField()
>termination_date= models.IntegerField(null = True,
> blank = True)
>bio = models.TextField()
>photopath   = models.CharField(max_length = 5048)
>office_phone= models.CharField(max_length=12)
>email   = models.CharField(max_length = 256)
>preferred_name  = models.CharField(max_length = 50,
> null = True, blank = True)
>deleted = models.BooleanField(default = False)
>viewable= models.BooleanField(default = True)
>
>class Meta:
>db_table = "n_test_staff"
>
> class TG_Staff(models.Model):
>g_name  = models.CharField(primary_key = True,
> max_length = 1024)
>g_modification_time = models.IntegerField()
>g_active= models.CharField(max_length = 5)
>g_common_name   = models.CharField(max_length = 1024)
>g_phone_number  = models.CharField(max_length = 1024)
>g_default_project   = models.CharField(max_length = 1024)
>g_office_address= models.CharField(max_length = 1024)
>g_bz_phone  = models.CharField(max_length = 1024)
>g_bz_phone_ext  = models.CharField(max_length = 1024)
>g_citizenship   = models.CharField(max_length = 1024)
>g_street_address= models.CharField(max_length = 1024)
>g_street_address2   = models.CharField(max_length = 1024)
>g_city  = models.CharField(max_length = 1024)
>g_state = models.CharField(max_length = 1024)
>g_zip   = models.CharField(max_length = 1024)
>g_country   = models.CharField(max_length = 1024)
>g_dept  = models.CharField(max_length = 1024)
>g_tg_person_id  = models.CharField(max_length = 1024)
>g_org   = models.CharField(max_length = 1024)
>g_position  = models.CharField(max_length = 1024)
>   

Re: Relation not found error while dealing with foreign keys and forms

2011-11-03 Thread Furbee
Hi Tabitha,

I wish I could supply a quick and simple answer to fix what's going on in
your database, but nothing obvious is standing out. Can you supply your
model for StaffForm? That seems to be where the problem lies, since we can
get details from the model and view elsewhere.

Thanks,

Furbee

On Thu, Nov 3, 2011 at 7:22 PM, Tabitha Samuel wrote:

> K, so that worked...
>
> This is what I got:
> In [5]: i = Staff.objects.using('gold').get(username='tsamuel')
>
> In [6]: i.nics_group.n_group_name
> Out[6]: u'Systems and Operations'
>
> Looks like the foreign key is working fine from the db's perspective.
> This is how I'm getting the form:
> form = StaffForm(instance = Staff.objects.using('gold').get(username
> =current_staff))
> where current_staff = 'tsamuel'
> and then if I do a print form, I get a relation n_nics_groups does not
> exist error.
>
> Once again, thank you so much for your help, I really appreciate it!
>
> Tabitha
>
> On Nov 3, 1:26 pm, Furbee  wrote:
> > I may have lead you astray. I set up the same models on my end and get
> the
> > same query; it didn't show the join of the foreign key in the QuerySet of
> > Staff, but when I did a get() on username='tsamuel' I got a Staff object.
> > Then I was able to get the group they belonged to. This was successful
> for
> > me:
> >
> > Here's my data:
> >
> > table: n_nics_groups
> > n_group_number; n_group_name
> > 1; "TestGroup1"
> > 2; "TestGroup2"
> > 3; "TestGroup3"
> >
> > table: n_test_staff
> >
> "tfigura";"";"";"";"";"";"";"";"";2;"";"''";"";"";"";1;1;1;;"''";"''";"''";"''";"";FALSE;TRUE
> >
> "tsamuel";"";"";"";"";"";"";"";"";1;"";"''";"";"";"";1;1;1;;"''";"''";"''";"''";"''";FALSE;TRUE
> >
> > 'tfigura' is in group with n_group_number 2, tsamuel is in group with
> > n_group_number 1.
> >
> > python manage.py shell:
> >
> > >>> from project.models import NICSGroupType, Staff
> > >>> i = Staff.objects.get(username='tsamuel')
> > >>> i.nics_group.n_group_name
> > >>> u'TestGroup1'
> >
> > Is this operational for your instance? If not, I would double check that
> > the n_nics_groups table definitely exists in the datasource you defined
> as
> > 'gold.' This should be defined in the DATABASES section of settings.py.
> It
> > looks like it is the database 'public' from your example, but double
> check
> > that the 'gold' DATABASE points there.
> >
> > Otherwise, I wonder if it is somewhere where you are defining the form
> > object. First, let's verify that the foreign key reference is being
> honored
> > on your system, by running the above test, to verify that the group is
> > printed, when you get() a specific record and print the
> > nics_group.n_group_name.
> >
> > Thanks,
> >
> > Furbee
> >
> > On Wed, Nov 2, 2011 at 5:09 PM, Tabitha Samuel 
> > wrote:>
> Thank you so much for your reply! So I got a "Staff object has no
> > > attribute 'query'" error when I did it with the get. I got the sql
> > > when I tried it with the filter instead (instance =
> > > Staff.objects.using('gold').filter(username='tsamuel') >>
> > > str(instance.query))this is what I'm getting:
> >
> > > 'SELECT "n_test_staff"."username", "n_test_staff"."home_phone",
> > > "n_test_staff"."cell_phone", "n_test_staff"."home_address",
> > > "n_test_staff"."home_city", "n_test_staff"."home_state",
> > > "n_test_staff"."home_zip", "n_test_staff"."emergency_name",
> > > "n_test_staff"."emergency_phone", "n_test_staff"."nics_group",
> > > "n_test_staff"."room_number", "n_test_staff"."title",
> > > "n_test_st

Re: Relation not found error while dealing with foreign keys and forms

2011-11-03 Thread Furbee
I may have lead you astray. I set up the same models on my end and get the
same query; it didn't show the join of the foreign key in the QuerySet of
Staff, but when I did a get() on username='tsamuel' I got a Staff object.
Then I was able to get the group they belonged to. This was successful for
me:

Here's my data:

table: n_nics_groups
n_group_number; n_group_name
1; "TestGroup1"
2; "TestGroup2"
3; "TestGroup3"

table: n_test_staff
"tfigura";"";"";"";"";"";"";"";"";2;"";"''";"";"";"";1;1;1;;"''";"''";"''";"''";"";FALSE;TRUE
"tsamuel";"";"";"";"";"";"";"";"";1;"";"''";"";"";"";1;1;1;;"''";"''";"''";"''";"''";FALSE;TRUE

'tfigura' is in group with n_group_number 2, tsamuel is in group with
n_group_number 1.

python manage.py shell:
>>> from project.models import NICSGroupType, Staff
>>> i = Staff.objects.get(username='tsamuel')
>>> i.nics_group.n_group_name
>>> u'TestGroup1'

Is this operational for your instance? If not, I would double check that
the n_nics_groups table definitely exists in the datasource you defined as
'gold.' This should be defined in the DATABASES section of settings.py. It
looks like it is the database 'public' from your example, but double check
that the 'gold' DATABASE points there.

Otherwise, I wonder if it is somewhere where you are defining the form
object. First, let's verify that the foreign key reference is being honored
on your system, by running the above test, to verify that the group is
printed, when you get() a specific record and print the
nics_group.n_group_name.

Thanks,

Furbee

On Wed, Nov 2, 2011 at 5:09 PM, Tabitha Samuel wrote:

> Thank you so much for your reply! So I got a "Staff object has no
> attribute 'query'" error when I did it with the get. I got the sql
> when I tried it with the filter instead (instance =
> Staff.objects.using('gold').filter(username='tsamuel') >>
> str(instance.query))this is what I'm getting:
>
> 'SELECT "n_test_staff"."username", "n_test_staff"."home_phone",
> "n_test_staff"."cell_phone", "n_test_staff"."home_address",
> "n_test_staff"."home_city", "n_test_staff"."home_state",
> "n_test_staff"."home_zip", "n_test_staff"."emergency_name",
> "n_test_staff"."emergency_phone", "n_test_staff"."nics_group",
> "n_test_staff"."room_number", "n_test_staff"."title",
> "n_test_staff"."supervisor", "n_test_staff"."url",
> "n_test_staff"."im", "n_test_staff"."last_modification_time",
> "n_test_staff"."start_date", "n_test_staff"."creation_time",
> "n_test_staff"."termination_date", "n_test_staff"."bio",
> "n_test_staff"."photopath", "n_test_staff"."office_phone",
> "n_test_staff"."email", "n_test_staff"."preferred_name",
> "n_test_staff"."deleted", "n_test_staff"."viewable" FROM
> "n_test_staff" WHERE "n_test_staff"."username" = tsamuel '
>
> Looks like from the query, is not looking into the n_nics_groups
> table. Question is why?
>
> Tabitha
>
> On Nov 2, 6:00 pm, Furbee  wrote:
> > Can you try this and tell us what you see:
> >
> > Run a shell using python manage.py shell
> >
> > >>> instance = Staff.objects.using('gold').get(username='tsamuel')
> > >>> str(instance.query)
> >
> > This will tell us whether or not the database, reference, and such are
> > correctly translating into a query. The error means Django is sending an
> > erroneous query to your database layer.
> >
> > Furbeenator
> >
> > On Wed, Nov 2, 2011 at 1:54 PM, Tabitha Samuel  >wrote:
> >
> >
> >
> >
> >
> >
> >
> > > Hi,
> >
> > > In brief here is my problem. I have two simpl

Re: Relation not found error while dealing with foreign keys and forms

2011-11-02 Thread Furbee
Can you try this and tell us what you see:

Run a shell using python manage.py shell
>>> instance = Staff.objects.using('gold').get(username='tsamuel')
>>> str(instance.query)

This will tell us whether or not the database, reference, and such are
correctly translating into a query. The error means Django is sending an
erroneous query to your database layer.

Furbeenator

On Wed, Nov 2, 2011 at 1:54 PM, Tabitha Samuel wrote:

> Hi,
>
> In brief here is my problem. I have two simple tables, one has a one
> to many relation with the other. The problem I run into is that when I
> try to create a form instance of the child, and try to print it or
> render it in a template, I run into a "relation not found" error for
> the parent. Simply querying the parent works without a problem.
>
> This is what my models.py looks like:
> from django.db import models
>
> class NICSGroupType(models.Model):
> n_group_number = models.IntegerField(primary_key = True)
>n_group_name = models.CharField(max_length = 512)
>class Meta:
>db_table = "n_nics_groups"
>
> class Staff(models.Model):
>username= models.CharField(primary_key = True,
> max_length = 50)
>home_phone  = models.CharField(max_length = 12,
> null=True)
>cell_phone  = models.CharField(max_length = 12,
> null = True)
>home_address= models.CharField(max_length = 1024,
> null = True)
>home_city   = models.CharField(max_length = 64,
> null = True)
>home_state  = models.CharField(max_length = 32,
> null = True)
>home_zip= models.CharField(max_length = 10,
> null = True)
>emergency_name  = models.CharField(max_length =64,
> null = True)
>emergency_phone = models.CharField(max_length = 12,
> null = True)
>nics_group  = models.ForeignKey(NICSGroupType,
> to_field ='n_group_number', db_column="nics_group",
> null=True,blank=True)
>room_number = models.CharField(max_length = 32,
> null = True)
>title   = models.CharField(max_length = 64)
>supervisor  = models.CharField(max_length = 25,
> null = True, blank = True)
>url = models.CharField(max_length =
> 256,null = True, blank = True)
>im  = models.CharField(max_length = 32,
> null = True, blank=True)
>last_modification_time  = models.IntegerField()
>start_date  = models.IntegerField()
>creation_time   = models.IntegerField()
>termination_date= models.IntegerField(null = True,
> blank = True)
>bio = models.TextField()
>photopath   = models.CharField(max_length = 5048)
>office_phone= models.CharField(max_length=12)
>email   = models.CharField(max_length = 256)
>preferred_name  = models.CharField(max_length = 50,
> null = True, blank = True)
>deleted = models.BooleanField(default = False)
>viewable= models.BooleanField(default = True)
>
>class Meta:
>db_table = "n_test_staff"
>
> The tables that it corresponds to looks like this:
>
>  \d n_test_staff
> Table "public.n_test_staff"
> Column |  Type  | Modifiers
> ++---
>  username   | character varying(25)  |
>  home_phone | character varying(12)  |
>  cell_phone | character varying(12)  |
>  home_address   | character varying(256) |
>  home_city  | character varying(64)  |
>  home_state | character varying(32)  |
>  home_zip   | character varying(10)  |
>  emergency_name | character varying(64)  |
>  emergency_phone| character varying(12)  |
>  nics_group | integer|
>  room_number| character varying(32)  |
>  title  | character varying(64)  |
>  supervisor | character varying(25)  |
>  url| character varying(256) |
>  im | character varying(32)  |
>  last_modification_time | integer|
>  start_date | integer|
>  creation_time  | integer|
>  termination_date   | integer|
>  bio| text   |
>  photopath  | text   |
>  office_phone   | character varying(12)  |
>  email  | text   |
>  preferred_name | character varying(50)  |
>  deleted| boolean|
>  viewable   | boolean|
> Foreign-key constraints:
>"nics_group_fkey" FOREIGN KEY (nics_group) REFERENCES
> n_nics_groups(n_gr

Re: Formwizard - Many2Many field - instance needs to have a primary key value before a many-to-many relationship can be used

2011-11-02 Thread Furbee
Hi Alain,

Sort of. With this code:
if field == 'category':
instance.save()
a Customer with 50 categories would write to the database 51 times (1
INSERT, and 50 UPDATES).

Including the "instance.id == None" like this:
if field == 'category' and instance.id == None:
instance.save()
will make it write to the database one or two times maximum. If the
Customer has 0 categories, it will write once (INSERT at bottom of
program). If the Customer has n categories, it will only write once
(INSERT) in the loops, and write once (UPDATE) at the bottom of the program.

That is why it is much quicker running it this way.

Cheers,

Furbeenator

On Wed, Nov 2, 2011 at 1:00 PM, youpsla  wrote:

> Hi again
> thanks for explanations.
>
> I've understood difference between Null and None.
>
> I've modify the code to add "instance.id == Non" and it seems to be
> faster.
>
> To be sure. You mean that if a customer has 1 category, there will be
> 2 database access (one for all informations except category and one
> for category).
>
> If a customer has 50 categories, then it's 51 database access ? hu
>
>
> Thanks again
>
> Alain
>
>
>
> On 2 nov, 20:11, Furbee  wrote:
> > Hi Alain,
> >
> > Glad that it worked out! :-)
> >
> > To clarify, a blank is different from a Null, or "None" in
> Python/Django. A
> > blank character field is "" where a null character field is NULL. If a
> > field does not specify null=True, and you try to save an instance of that
> > object without specifying that field, it will raise a Database error. So,
> > in your loop if you hit category first, before any other fields, it would
> > try to save the instance of the Customer without specifying all of the
> > fields needed. That is why category must come AFTER all other fields that
> > are required (not null=True).
> >
> > You are correct. The instance = Customer() creates a new customer object,
> > when you executed instance.save() the instance information is saved
> > (INSERT) to the database, and it received a PK (id). Every subsequent
> > instance.save() actually runs (UPDATE) on the database, updating all
> fields
> > in the instance. If you have a whole lot of fields in the Customer, one
> > optimization would be to add logic to the loop that if the field is
> > 'category' and the instance has not yet been saved, save it. This way it
> is
> > only saved once before adding category and once at the end of setting all
> > attributes. This will probably be a better solution, and will hit the
> > database only twice instead of +1 times:
> >
> > class InscriptionWizard(SessionWizardView):
> > def done(self, form_list, **kwargs):
> > instance = Customer()
> > for form in form_list:
> > for field, value in form.cleaned_data.iteritems():
> > if field == 'category' and instance.id == None: # if
> this
> > is a category, and the instance has not yet been saved, save it so it has
> > an id.
> > instance.save()
> > setattr(instance, field, value)
> > instance.save()
> >
> > Happy coding!
> >
> > Furbeenator
> >
> >
> >
> >
> >
> >
> >
> > On Wed, Nov 2, 2011 at 12:00 PM, youpsla  wrote:
> > > Oupsss, another question in the step by step:
> >
> > > 1 class InscriptionWizard(SessionWizardView):
> > > 2def done(self, form_list, **kwargs):
> > > 3instance = Customer()
> > > 4for form in form_list:
> > > 5for field, value in form.cleaned_data.iteritems():
> > > 6if field == 'category':
> > > 7instance.save()
> > > 8setattr(instance, field, value)
> > > 9instance.save()
> >
> > > Line 7 : Will save in the DB all fields that have been already
> > > iterated. Then I suppose the instance.save() will not clear
> > > informations affected by the setattr() otherwise the PK is lost ...
> > > and the Line 9 doesn't know wich PK to use 
> >
> > > Then I suppose the Line 9 will save all informations of the form,
> > > those which have been already saved by Line 7 and add category. Then I
> > > suppose Django will perform an "UPDATE" rather than an "INSERT" SQL
> > > statement ?
> >
> > > Is it right ?
> >
> > > Again, regards for the time spend to answer.
> >

Re: Formwizard - Many2Many field - instance needs to have a primary key value before a many-to-many relationship can be used

2011-11-02 Thread Furbee
Hi Alain,

Glad that it worked out! :-)

To clarify, a blank is different from a Null, or "None" in Python/Django. A
blank character field is "" where a null character field is NULL. If a
field does not specify null=True, and you try to save an instance of that
object without specifying that field, it will raise a Database error. So,
in your loop if you hit category first, before any other fields, it would
try to save the instance of the Customer without specifying all of the
fields needed. That is why category must come AFTER all other fields that
are required (not null=True).

You are correct. The instance = Customer() creates a new customer object,
when you executed instance.save() the instance information is saved
(INSERT) to the database, and it received a PK (id). Every subsequent
instance.save() actually runs (UPDATE) on the database, updating all fields
in the instance. If you have a whole lot of fields in the Customer, one
optimization would be to add logic to the loop that if the field is
'category' and the instance has not yet been saved, save it. This way it is
only saved once before adding category and once at the end of setting all
attributes. This will probably be a better solution, and will hit the
database only twice instead of +1 times:

class InscriptionWizard(SessionWizardView):
def done(self, form_list, **kwargs):
instance = Customer()
for form in form_list:
for field, value in form.cleaned_data.iteritems():
if field == 'category' and instance.id == None: # if this
is a category, and the instance has not yet been saved, save it so it has
an id.
instance.save()
setattr(instance, field, value)
instance.save()

Happy coding!

Furbeenator


On Wed, Nov 2, 2011 at 12:00 PM, youpsla  wrote:

> Oupsss, another question in the step by step:
>
> 1 class InscriptionWizard(SessionWizardView):
> 2def done(self, form_list, **kwargs):
> 3instance = Customer()
> 4for form in form_list:
> 5for field, value in form.cleaned_data.iteritems():
> 6if field == 'category':
> 7instance.save()
> 8setattr(instance, field, value)
> 9instance.save()
>
> Line 7 : Will save in the DB all fields that have been already
> iterated. Then I suppose the instance.save() will not clear
> informations affected by the setattr() otherwise the PK is lost ...
> and the Line 9 doesn't know wich PK to use 
>
> Then I suppose the Line 9 will save all informations of the form,
> those which have been already saved by Line 7 and add category. Then I
> suppose Django will perform an "UPDATE" rather than an "INSERT" SQL
> statement ?
>
> Is it right ?
>
>
> Again, regards for the time spend to answer.
>
> Alain
>
> On 2 nov, 19:03, Furbee  wrote:
> > In your Customer model there are fields which cannot be Null, so you
> cannot
> > instance.save() before setting those properties. So, you may have to
> check
> > for the category field in your loop and if it is category, save the
> > instance first. Something like the following:
> >
> > views.py (in clients application)
> > -
> > class InscriptionWizard(SessionWizardView):
> >def done(self, form_list, **kwargs):
> >instance = Customer()
> >for form in form_list:
> >for field, value in form.cleaned_data.iteritems():
> >if field == 'category':
> >instance.save()
> >setattr(instance, field, value)
> >instance.save()
> > -
> >
> > This would of course depend on your ordering of the fields. In other
> words,
> > category would have to be the first Allow Null field in your model,
> because
> > you cannot save() until all Not Null fields have a value. If you cannot
> > order these fields so the category is last, you may have to do something
> > like:
> >
> > views.py (in clients application)
> > -
> > class InscriptionWizard(SessionWizardView):
> >def done(self, form_list, **kwargs):
> >instance = Customer()
> >for form in form_list:
> >for field, value in form.cleaned_data.iteritems():
> >if field != 'category':
> >setattr(instance, field, value)
> >instance.save()
> >for form in form_list:
> >for field, value in form.cleaned_data.iteritems():
> >if field == &

Re: QuerySet: "if obj in queryset" can be very slow

2011-11-02 Thread Furbee
Thanks Tom, that's a great explanation!

Furbeenator

On Wed, Nov 2, 2011 at 10:46 AM, Tom Evans  wrote:

> On Wed, Nov 2, 2011 at 5:30 PM, Ian Clelland  wrote:
> > On Wed, Nov 2, 2011 at 8:25 AM, Thomas Guettler  wrote:
> >>
> >> # This is my current solution
> >> if get_special_objects().filter(pk=obj.pk).count():
> >># yes, it is special
> >>
> >
> > I can't speak to the "why" of this situation; it seems to me that this
> could
> > always be converted into a more efficient database query without any
> > unexpected side-effects (and if I really wanted the side effects, I would
> > just write "if obj in list(qs)" instead). In this case, though, I would
> > usually write something like this:
> > if get_special_objects().filter(pk=obj.pk).exists():
> ># yes, it is special
> > I believe that in some cases, the exists() query can be optimized to
> return
> > faster than a count() aggregation, and I think that the intent of the
> code
> > appears more clearly.
> > Ian
>
> OK, take this example. I have a django model table with 70 million
> rows in it. Doing any kind of query on this table is slow, and
> typically the query is date restrained - which mysql will use as the
> optimum key, meaning any further filtering is a table scan on the
> filtered rows.
>
> Pulling a large query (say, all logins in a month, ~1 million rows)
> takes only a few seconds longer than counting the number of rows the
> query would find - after all, the database still has to do precisely
> the same amount of work, it just doesn't have to deliver the data.
>
> Say I have a n entries I want to test are in that resultset, and I
> also want to iterate through the list, calculating some data and
> printing out the row, I can do the existence tests either in python or
> in the database. If I do it in the database, I have n+1 expensive
> queries to perform. If I do it in python, I have 1 expensive query to
> perform, and (worst case) n+1 full scans of the data retrieved (and I
> avoid locking the table for n+1 expensive queries).
>
> Depending on the size of the data set, as the developer I have the
> choice of which will be more appropriate for my needs. Sometimes I
> need "if qs.filter(pk=obj.pk).exists()", sometimes I need "if obj in
> qs".
>
> Cheers
>
> Tom
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Formwizard - Many2Many field - instance needs to have a primary key value before a many-to-many relationship can be used

2011-11-02 Thread Furbee
In your Customer model there are fields which cannot be Null, so you cannot
instance.save() before setting those properties. So, you may have to check
for the category field in your loop and if it is category, save the
instance first. Something like the following:

views.py (in clients application)
-
class InscriptionWizard(SessionWizardView):
   def done(self, form_list, **kwargs):
   instance = Customer()
   for form in form_list:
   for field, value in form.cleaned_data.iteritems():
   if field == 'category':
   instance.save()
   setattr(instance, field, value)
   instance.save()
-

This would of course depend on your ordering of the fields. In other words,
category would have to be the first Allow Null field in your model, because
you cannot save() until all Not Null fields have a value. If you cannot
order these fields so the category is last, you may have to do something
like:

views.py (in clients application)
-
class InscriptionWizard(SessionWizardView):
   def done(self, form_list, **kwargs):
   instance = Customer()
   for form in form_list:
   for field, value in form.cleaned_data.iteritems():
   if field != 'category':
   setattr(instance, field, value)
   instance.save()
   for form in form_list:
   for field, value in form.cleaned_data.iteritems():
   if field == 'category':
   setattr(instance, field, value)
-

I'm sure there is a MUCH more elegant way of getting just the categories
from the forms and field/value pairs, this is brute force (not very
scalable for large number of fields), but should work. Anybody else please,
show code that could get the specific forms and field/values for categories.

Furbeenator


On Wed, Nov 2, 2011 at 10:28 AM, youpsla  wrote:

> Hello,
> i'm currently doning a website where user can register (without
> password, without auth module of Django). They put some informations
> and at the end (Step5Form) do multiple choices by clicking on
> checkboxes. When I click on validate on the last step I've "instance
> needs to have a primary key value before a many-to-many relationship
> can be used" error. I've search the web to find a solution but . :-
> (
>
> Here is my code:
>
> models.py for Customer (in clients application)
> -
> class Customer (models.Model):
>
>email_adresse = models.EmailField(max_length=255, unique=True)
>some fields . for Step2 to Step4 of the form
>category = models.ManyToManyField(Categories)
> -
>
> models.py for categories (in categories application)
> -
> class Categories (models.Model):
>category = models.CharField(max_length=200)
>
>def __unicode__(self):
>return unicode(self.category)
> -
>
> The ManyToMany field has created(syncdb) a table
> clients_customer_category with the following columns:
>1   id  int(11)
> AUTO_INCREMENT
>2   customer_id int(11)
>3   categories_id   int(11)
>
>
> urls.py
> -
> urlpatterns = patterns('',
>(r'^clients/$', InscriptionWizard.as_view([Step1Form, Step2Form,
> Step3Form, Step4Form, Step5Form])),
> )
> -
>
>
> forms.py (in clients application)
> -
> from django import forms
> from clients.models import Customer
> from categories.models import Categories
>
> class Step1Form(forms.Form):
>email_adresse = forms.EmailField(max_length=255)
>
> class Step5Form(forms.Form):
>category =
> forms.ModelMultipleChoiceField(queryset=Categories.objects.all(),
> widget=forms.CheckboxSelectMultiple, required=True)
>
>
> views.py (in clients application)
> -
> class InscriptionWizard(SessionWizardView):
>def done(self, form_list, **kwargs):
>instance = Customer()
>for form in form_list:
>for field, value in form.cleaned_data.iteritems():
>setattr(instance, field, value)
>instance.save()
> -
>
> I got the following error:
> -
> Request Method: POST
> Request URL:http://127.0.0.1:8010/clients/
> Django Version: 1.3.1
> Exception Type: ValueError
> Exception Value:
> 'Customer' instance needs to have a primary key value before a many-to-
> many relationship can be used.
> ...
> ...
> ▶ Local vars
> C:\dev\Flash\clients\views.py in done
>setattr(instance, field, valu

Re: Calling Python from JavaScript

2011-11-02 Thread Furbee
You could call the Dajaxice method that gets the result (the one that fires
when the drop down changes) with window.onload, or you could pass the
initial values to the template via the view. For consistency and code
reuse, I would personally use the first method, calling the Dajaxice
function responsible for calculating the result with window.onload. If the
method is currently accepting the drop-down's value as an argument, you
would have to change it to actively find the selected values of the
drop-downs manually from the javascript function.

Furbeenator

On Wed, Nov 2, 2011 at 2:31 AM, asif  wrote:

> I will explain what i'm trying to achieve, I'm using Dajaxice with
> Django.
>
> I created modelformset which consist of multiple forms. Each form has
> dropdown field on which I'm calling dajaxice function, that function
> will takes the value of the dropdown field and calls another python
> function which calculates the total sum of all the values of dropdown
> fields. Here my formset has initial values. So I want to call that
> python function (which calculates result ) in javascript code (This
> javascript function is for dajaxice )
>
>
> Regards
>
> Asif
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Field available via Django shell but not via web application (crossposted from StackOverFlow)

2011-11-02 Thread Furbee
You said you are using django.contrib.auth.models.User as your User model,
but that doesn't have a "foos" property. Can you share the models that you
are using? Are you creating a subclass User that extends
django.contrib.auth.models.User and adds foos and a ForeignKey? Is foos a
ManyToManyField, OneToOneField, or just a ForeignKey to a Foos model which
has a name property?

Thanks,

Furbeenator

On Wed, Nov 2, 2011 at 8:27 AM, Jordan  wrote:

> Yes, it does work in runserver, as might be expected since runserver
> uses exact same environment as the shell.
>
> So that established, how can I fix it?
>
> On Nov 1, 9:04 pm, Andy McKay  wrote:
> > Is this using the Django built in runserver or some other way of serving
> > pages? If not try using runserver.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Onchange event on Choicefield in django formset

2011-11-02 Thread Furbee
I think your 'answer' is going to exist in POST in either case. Perhaps
change the construct of your logic to:

if 'evaluation' in request.POST:
return render_to_response('results.html')
elif 'form-0-answer' in request.POST:
answer = request.POST.get('answer','')
values.append(answer)
return render_to_response('success.html')

Furbeenator


On Wed, Nov 2, 2011 at 9:21 AM, Kurtis Mullins wrote:

> Try changing your success_url to this same page.
>
>
> On Wed, Nov 2, 2011 at 11:00 AM, asif.jama...@rezayat.net <
> asif.jama...@rezayat.net> wrote:
>
>> How can i access the form fields in django views.
>>
>> Suppose i have modelform called
>>
>>
>> class QuestionForm(forms.ModelForm):
>>
>>
>>  answer = forms.ChoiceField(choices=HAY_EVALUATION_CHOICES,
>>
>> widget=forms.Select(attrs={'onchange': 'this.form.submit();'}))
>>
>>
>> In views.py
>>
>>
>>  if 'form-0-answer' in request.POST:
>>
>>
>>answer = request.POST.get('answer','')
>>
>>
>>values.append(answer)
>>
>>
>>return render_to_response('success.html')
>>
>>
>> if 'evaluation' in request.POST:
>>
>> return render_to_response('results.html')
>>
>> The form consist of one submit button called 'evaluation' and second
>> is having onchange event on selection
>>
>> Here i'm trying to perform some operation on selection, then by using
>> second button that is 'evaluation' i will save the form.
>>
>> Here the problem is the form is always redirecting to success.html
>> even when i click 'evaluation' button
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django + Ajax/Javascript

2011-11-02 Thread Furbee
You could pass the values from the view to the template and use javascript
(I would suggest using jQuery) if there are only a few options. I would
suggest using Dajax (dajaxproject.com) for your AJAX commands. It is really
easy to plug into Django, and you should get familiar with it and the
jQuery javascript framework. They work very well for making the UI fun and
easy. There is also jQuery-UI which builds on the jQuery library with tons
more user interface options, like calendar pickers, sliders, etc. Good
stuff! :-)

Furbeenator

On Wed, Nov 2, 2011 at 5:42 AM, Felix Wagner wrote:

> Hi,
>
> I have the following model layout:
>
> class A(models.model):
>options = models.ManyToManyField(OptionSet, blank=True, null=True)
>values = models.ManyToManyField(Value, blank=True, null=True)
>
> class OptionSet(models.model):
>name = models.TextField(unique=True)
>values = models.ManyToManyField(Value)
>
>def __unicode__(self):
>return '%s' % self.name
>
> class Value(models.Model):
>name = models.TextField()
>key = models.ForeignKey(Key, related_name='values')
>
> class Key(models.Model):
>name = models.TextField(unique=True)
>
> And my forms.py looks like this:
>
> class A_Form(ModelForm):
>values =
> forms.ModelMultipleChoiceField(queryset=Value.objects.all(),
> widget=CheckboxSelectMultiple, label="Einzelne Werte", required=False)
>options =
> forms.ModelMultipleChoiceField(queryset=OptionSet.objects.all(),
> widget=CheckboxSelectMultiple, label="Optionen Sets", required=False)
>
> Template:
>
> {% csrf_token %}
>{{ form.as_table }}
>
> 
>
> I use that form with a generic update view! I'm new to javascript/ajax
> to be honest never did something in javascript/ajax. What I want to do
> is on mouseover on the options name it should show all the values for
> that option set. How would one accomplish this (either with or without
> ajax)?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Set of choices of which several can be chosen without using a ManyToManyField

2011-11-02 Thread Mark Furbee
As alluded to previously, the most "straightforward way to use a set of
choices of which several can be chosen" IS to use a ManyToManyField. The
syntax is slightly different, but ManyToManyFields are really easy to use
with Django. Do not reinvent the wheel in this case.

Thanks,

Mark Furbee


On Tue, Nov 1, 2011 at 7:49 AM, J. Cliff Dyer  wrote:

> On 11/01/2011 09:05 AM, Jaroslav Dobrek wrote:
>
>> You are confusing model fields with form fields. MultipleChoiceField
>>> is a form field, not a model field.
>>>
>> I wasn't aware of the existence of MultipleChoiceFields. The idea of
>> the above code was to express that I wanted to use this code
>>
>> class Candidate(models.Model):
>>
>> programming_languages = models.CharField(max_length=**50, choices=(
>>
>> (u'Python)', u'Python'),
>> (u'C++', u'C++'),
>> (u'Java', u'Java'),
>> # ...
>> ), blank=True)
>>
>> with the only exception that, in the admin interface, several choices
>> are possible when one creates a new candidate object. I.e. I want
>> admins to be able to create a candidate that knows, say Python *and* C+
>> + by choosing both of these languages during the creation of the
>> object. I used the string "MultipleChoiceField" as a dummy for
>> whatever should be used instead.
>>
>> Jaroslav
>>
>>
>>
>>
>>
>>
>>  If you want a field that will be represented by a MultipleChoiceField
>>> in model, you simply need to define 'choices' on a field class.
>>>
>>> https://docs.djangoproject.**com/en/1.3/ref/models/fields/#**choices<https://docs.djangoproject.com/en/1.3/ref/models/fields/#choices>
>>>
>>> Cheers
>>>
>>> Tom
>>>
>> Still, you want to control the input at the form level, not the model
> level.  Create a ModelForm for your Candidate, but override the language
> field to take a MultipleChoiceField, and then override the __init__() and
> save() methods to handle them properly.  "Properly," of course, is
> determined by your application, and how you want to store the information
> in the database.  You could choose to store it in a CharField as a comma
> separated list of language names, or in an IntegerField as a bit field (0x1
> = 'Python', 0x2 = 'Perl', 0x4 = PHP, so 0x5 means the user knows Python and
> PHP, but not Perl).  The latter is a more efficient way to store the data,
> but the former is arguably more human-friendly.
>
> Ultimately, though, it seems that you are adding complexity rather than
> removing it.  This is exactly what many to many relationships are designed
> to handle.  If you want to use another method, you have to figure out the
> details for yourself.
>
> Cheers,
> Cliff
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@**
> googlegroups.com .
> For more options, visit this group at http://groups.google.com/**
> group/django-users?hl=en<http://groups.google.com/group/django-users?hl=en>
> .
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.