Select Boxes and Database

2023-12-02 Thread David Merrick
Hi. I can put an item from the database into a select box ie Countries of
the World. What I want to know is saying, having chosen New Zealand from
the select box, how do I display all the cities of New Zealand in another
select box.

The database has two tables. First one is Countries. The second table is
cities with populations and the foreign key of Countries table.

Then having chosen Auckland a city in New Zealand I want to display

Country
City
Population

In a template.

I have done this in Php, Javascript and Mysql already.

Cheers Dave


-- 
Dave Merrick

TutorInvercargill

http://tutorinvercargill.co.nz

Daves Web Designs

Website https://tutorinvercargill.co.nz/daveswebdesigns/public_html/

Email merrick...@gmail.com

Ph   03 216 2053

Cell 027 3089 169

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2B%3DMcKYDfzhvQ8ueCKKccYX3gcQUmfoX9NXipqf%3DDipsXPzG7g%40mail.gmail.com.


Re: Domain Names and Web Servers

2020-05-08 Thread David Merrick
Ok to rephrase the Question whats a typical set up for Django Web for say
Website
Web Servers and Domain Name Servers.

For example for Rails I could use Heroku fro the Hosting
https://www.heroku.com/
For the Domain Name Server I could use Domains4less
https://www.domains4less.co.nz/
but Domain4less can't use Dynamic IP address so the two are related sorry.

On Sat, May 9, 2020 at 10:14 AM Kasper Laudrup 
wrote:

> Hi David,
>
> On 08/05/2020 23.18, David Merrick wrote:
> > Hi, I am interested in what web servers can be used for Django Web Apps
> > and whether the Domain Name Servers are Static or Dynamic. Static Domain
> > Name Servers (DNS) the IP Address doesn't change and Dynamic (DNS) IP
> > Address does change.
> >
>
> That is really two completely unrelated questions.
>
> For deployment you can use quite a few different web servers, but it
> really depends on your requirements:
>
> https://docs.djangoproject.com/en/3.0/howto/deployment/
>
> Django doesn't know anything about domain servers, that's not really
> related at all.
>
> To be a bit pedantic, there really isn't any difference between a
> dynamic and a static DNS server. DNS just resolves host names to IP
> addresses (and more, but that's not relevant). Some DNS records just
> have a low TTL meaning that the information provided changes more often
> making them more "dynamic".
>
> How you decide to handle that also depends on your requirements and most
> likely how you decide to host your Django application.
>
> Hope that helps.
>
> Kind regards,
>
> Kaspr Laudrup
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/2Tx8UU5K-n0/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c94d816f-b88b-feab-0a61-cd08718bc70f%40stacktrace.dk
> .
>


-- 
Dave Merrick

TutorInvercargill

http://tutorinvercargill.co.nz

Daves Web Designs

Website http://www.daveswebdesigns.co.nz

Email merrick...@gmail.com

Ph   03 216 2053

Cell 027 3089 169

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2B%3DMcKZm7hSGRE_Wa7%2BDhJM%3D9LBdixuXL6qmUWamaf-9OXTm2A%40mail.gmail.com.


Domain Names and Web Servers

2020-05-08 Thread David Merrick
Hi, I am interested in what web servers can be used for Django Web Apps and 
whether the Domain Name Servers are Static or Dynamic. Static Domain Name 
Servers (DNS) the IP Address doesn't change and Dynamic (DNS) IP Address 
does change.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0453cae2-7f58-4459-b03f-aa84969bd422%40googlegroups.com.


Re: Django Lessons

2020-05-08 Thread David Merrick
I am asking  about web hosting and appropriate Domain Name Servers

On Fri, May 8, 2020 at 9:18 PM David Merrick  wrote:

> Same Domain Name Servers can only handle
> static DNS server
> https://ticket.cdmon.com/en/support/solutions/articles/706124-what-is-a-static-dns-server-and-where-to-modify-dns-records
>
> Some can Domain Name Servers can only handle
> https://en.wikipedia.org/wiki/Dynamic_DNS
>
> So do  Apache (mod_wsgi), Gunicorn, and uWSGI  use Static or Dynamic
> Domain Name Servers?
>
>
>
>
> On Fri, May 8, 2020 at 6:49 PM Eugen Ciur  wrote:
>
>> For first part of the question: Apache (mod_wsgi), Gunicorn, and uWSGI
>> are most popular choices
>> I don't second part of question though - what you mean with "and what
>> domain names / types" ?
>>
>> On Friday, May 8, 2020 at 8:33:43 AM UTC+2, David Merrick wrote:
>>>
>>> Sounds like a very good idea.
>>> I have one immediate question. What web servers can host Django and what
>>> Domain Names / types?
>>> I was using Rails for a bit but got unstuck when Rails need Dynamic
>>> Domain Names, not Static ones.
>>>
>>> Cheers Dave
>>>
>>> On Fri, May 8, 2020 at 6:11 PM Eugen Ciur  wrote:
>>>
>>>> Hi,
>>>>
>>>> on https://django-lessons.com I release weekly screencasts about
>>>> Django Web Framework. Lessons are usually very short, around 10 minutes.
>>>> Each of them focuses on a single practical topic so that you can
>>>> immediately apply learned skills in your projects.
>>>> 50% of all content always will be free.
>>>>
>>>> I would love your feedback!
>>>>
>>>> Regards,
>>>> Eugen / Django Lessons
>>>>
>>>> --
>>>> 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...@googlegroups.com.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/784e88d9-9a3d-45ea-b43d-6d22b54469b2%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/django-users/784e88d9-9a3d-45ea-b43d-6d22b54469b2%40googlegroups.com?utm_medium=email_source=footer>
>>>> .
>>>>
>>>
>>>
>>> --
>>> Dave Merrick
>>>
>>> TutorInvercargill
>>>
>>> http://tutorinvercargill.co.nz
>>>
>>> Daves Web Designs
>>>
>>> Website http://www.daveswebdesigns.co.nz
>>>
>>> Email merri...@gmail.com
>>>
>>> Ph   03 216 2053
>>>
>>> Cell 027 3089 169
>>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/360c1be4-e868-42b1-a22a-a0246a3b2791%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/360c1be4-e868-42b1-a22a-a0246a3b2791%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>
>
> --
> Dave Merrick
>
> TutorInvercargill
>
> http://tutorinvercargill.co.nz
>
> Daves Web Designs
>
> Website http://www.daveswebdesigns.co.nz
>
> Email merrick...@gmail.com
>
> Ph   03 216 2053
>
> Cell 027 3089 169
>


-- 
Dave Merrick

TutorInvercargill

http://tutorinvercargill.co.nz

Daves Web Designs

Website http://www.daveswebdesigns.co.nz

Email merrick...@gmail.com

Ph   03 216 2053

Cell 027 3089 169

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2B%3DMcKZfnhJuG4wytiEzMuPp%3D5UN4FjMreafwBRUmv1qUVw8Og%40mail.gmail.com.


Re: Django Lessons

2020-05-08 Thread David Merrick
Same Domain Name Servers can only handle
static DNS server
https://ticket.cdmon.com/en/support/solutions/articles/706124-what-is-a-static-dns-server-and-where-to-modify-dns-records

Some can Domain Name Servers can only handle
https://en.wikipedia.org/wiki/Dynamic_DNS

So do  Apache (mod_wsgi), Gunicorn, and uWSGI  use Static or Dynamic Domain
Name Servers?




On Fri, May 8, 2020 at 6:49 PM Eugen Ciur  wrote:

> For first part of the question: Apache (mod_wsgi), Gunicorn, and uWSGI are
> most popular choices
> I don't second part of question though - what you mean with "and what
> domain names / types" ?
>
> On Friday, May 8, 2020 at 8:33:43 AM UTC+2, David Merrick wrote:
>>
>> Sounds like a very good idea.
>> I have one immediate question. What web servers can host Django and what
>> Domain Names / types?
>> I was using Rails for a bit but got unstuck when Rails need Dynamic
>> Domain Names, not Static ones.
>>
>> Cheers Dave
>>
>> On Fri, May 8, 2020 at 6:11 PM Eugen Ciur  wrote:
>>
>>> Hi,
>>>
>>> on https://django-lessons.com I release weekly screencasts about Django
>>> Web Framework. Lessons are usually very short, around 10 minutes.
>>> Each of them focuses on a single practical topic so that you can
>>> immediately apply learned skills in your projects.
>>> 50% of all content always will be free.
>>>
>>> I would love your feedback!
>>>
>>> Regards,
>>> Eugen / Django Lessons
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/784e88d9-9a3d-45ea-b43d-6d22b54469b2%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/784e88d9-9a3d-45ea-b43d-6d22b54469b2%40googlegroups.com?utm_medium=email_source=footer>
>>> .
>>>
>>
>>
>> --
>> Dave Merrick
>>
>> TutorInvercargill
>>
>> http://tutorinvercargill.co.nz
>>
>> Daves Web Designs
>>
>> Website http://www.daveswebdesigns.co.nz
>>
>> Email merri...@gmail.com
>>
>> Ph   03 216 2053
>>
>> Cell 027 3089 169
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/360c1be4-e868-42b1-a22a-a0246a3b2791%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/360c1be4-e868-42b1-a22a-a0246a3b2791%40googlegroups.com?utm_medium=email_source=footer>
> .
>


-- 
Dave Merrick

TutorInvercargill

http://tutorinvercargill.co.nz

Daves Web Designs

Website http://www.daveswebdesigns.co.nz

Email merrick...@gmail.com

Ph   03 216 2053

Cell 027 3089 169

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2B%3DMcKZfH4L4Eg5k1M_40x9oS_rZ8iYfuC_2TfWOFV3%2By9Tivg%40mail.gmail.com.


Re: Django Lessons

2020-05-08 Thread David Merrick
Sounds like a very good idea.
I have one immediate question. What web servers can host Django and what
Domain Names / types?
I was using Rails for a bit but got unstuck when Rails need Dynamic Domain
Names, not Static ones.

Cheers Dave

On Fri, May 8, 2020 at 6:11 PM Eugen Ciur  wrote:

> Hi,
>
> on https://django-lessons.com I release weekly screencasts about Django
> Web Framework. Lessons are usually very short, around 10 minutes.
> Each of them focuses on a single practical topic so that you can
> immediately apply learned skills in your projects.
> 50% of all content always will be free.
>
> I would love your feedback!
>
> Regards,
> Eugen / Django Lessons
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/784e88d9-9a3d-45ea-b43d-6d22b54469b2%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/784e88d9-9a3d-45ea-b43d-6d22b54469b2%40googlegroups.com?utm_medium=email_source=footer>
> .
>


-- 
Dave Merrick

TutorInvercargill

http://tutorinvercargill.co.nz

Daves Web Designs

Website http://www.daveswebdesigns.co.nz

Email merrick...@gmail.com

Ph   03 216 2053

Cell 027 3089 169

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2B%3DMcKZnGhvB8U3VtmakNBRdEjNdORbP16h6Ux2JmD3WaF0jCg%40mail.gmail.com.


Re: CSRF token still needed today?

2020-04-21 Thread David Merrick
Hi if you have an url with stuff?Stuff=Stuff the URL can be changed.
See the link below.
https://portswigger.net/web-security/csrf

On Wed, Apr 22, 2020 at 6:16 AM guettli 
wrote:

> Hi David, could you please explain how cross site forgery requests can
> happen
> with the current default for cookies (SameSite=Lax)?
>
> Am Montag, 20. April 2020 14:43:10 UTC+2 schrieb David Merrick:
>>
>> if you want cross site forgery requests get rid off it
>>
>> On Mon, Apr 20, 2020 at 10:45 PM Andréas Kühne 
>> wrote:
>>
>>> Why is it a problem to have? You add one specific command on all forms -
>>> or you disable it in the view
>>>
>>> What do you want to accomplish by removing it?
>>>
>>> Regards,
>>>
>>> Andréas
>>>
>>>
>>> Den sön 19 apr. 2020 kl 22:12 skrev guettli <
>>> guettl...@thomas-guettler.de>:
>>>
>>>> iI look at this page: https://docs.djangoproject.com/en/3.0/ref/csrf/
>>>> ... and then I look at this page:
>>>> https://scotthelme.co.uk/csrf-is-dead/
>>>>
>>>> Is a CSRF token still needed today?
>>>>
>>>> All my users use a modern browser.
>>>>
>>>> It would be very nice if I could get rid of the CSRF token.
>>>>
>>>> Is there a safe way to avoid CSRF tokens in  my Django project?
>>>>
>>>> Regards,
>>>>   Thomas
>>>>
>>>> --
>>>> 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...@googlegroups.com.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/487c7392-e874-4a1e-a1ff-488ab933ae42%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/django-users/487c7392-e874-4a1e-a1ff-488ab933ae42%40googlegroups.com?utm_medium=email_source=footer>
>>>> .
>>>>
>>> --
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAK4qSCeO0bkxsGYFc7t-V7%2BZnr965gYAG0oALB0ELtoJjojedg%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAK4qSCeO0bkxsGYFc7t-V7%2BZnr965gYAG0oALB0ELtoJjojedg%40mail.gmail.com?utm_medium=email_source=footer>
>>> .
>>>
>>
>>
>> --
>> Dave Merrick
>>
>> TutorInvercargill
>>
>> http://tutorinvercargill.co.nz
>>
>> Daves Web Designs
>>
>> Website http://www.daveswebdesigns.co.nz
>>
>> Email merri...@gmail.com
>>
>> Ph   03 216 2053
>>
>> Cell 027 3089 169
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c33f7b81-2e74-480c-b1fe-acd5f28468ac%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/c33f7b81-2e74-480c-b1fe-acd5f28468ac%40googlegroups.com?utm_medium=email_source=footer>
> .
>


-- 
Dave Merrick

TutorInvercargill

http://tutorinvercargill.co.nz

Daves Web Designs

Website http://www.daveswebdesigns.co.nz

Email merrick...@gmail.com

Ph   03 216 2053

Cell 027 3089 169

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2B%3DMcKa4bcep3kd1TUf54RdXepgQvNuXAkYGsUHOCi%3DBAPC0Gw%40mail.gmail.com.


Re: CSRF token still needed today?

2020-04-20 Thread David Merrick
if you want cross site forgery requests get rid off it

On Mon, Apr 20, 2020 at 10:45 PM Andréas Kühne 
wrote:

> Why is it a problem to have? You add one specific command on all forms -
> or you disable it in the view
>
> What do you want to accomplish by removing it?
>
> Regards,
>
> Andréas
>
>
> Den sön 19 apr. 2020 kl 22:12 skrev guettli <
> guettli.goo...@thomas-guettler.de>:
>
>> iI look at this page: https://docs.djangoproject.com/en/3.0/ref/csrf/
>> ... and then I look at this page: https://scotthelme.co.uk/csrf-is-dead/
>>
>> Is a CSRF token still needed today?
>>
>> All my users use a modern browser.
>>
>> It would be very nice if I could get rid of the CSRF token.
>>
>> Is there a safe way to avoid CSRF tokens in  my Django project?
>>
>> Regards,
>>   Thomas
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/487c7392-e874-4a1e-a1ff-488ab933ae42%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/487c7392-e874-4a1e-a1ff-488ab933ae42%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAK4qSCeO0bkxsGYFc7t-V7%2BZnr965gYAG0oALB0ELtoJjojedg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAK4qSCeO0bkxsGYFc7t-V7%2BZnr965gYAG0oALB0ELtoJjojedg%40mail.gmail.com?utm_medium=email_source=footer>
> .
>


-- 
Dave Merrick

TutorInvercargill

http://tutorinvercargill.co.nz

Daves Web Designs

Website http://www.daveswebdesigns.co.nz

Email merrick...@gmail.com

Ph   03 216 2053

Cell 027 3089 169

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2B%3DMcKa3X4o%3DEVkXvEpBaaCsVc8XKV7k-hDi9DXXEDJ%3Dxei44g%40mail.gmail.com.


Re: how to add a field to a model form when the field is not in the model

2010-04-07 Thread Merrick
Found the problem, thanks again for all of the help.

It turns out you have to define the extra field above def
__init__(self, *args, **kw) as in:

forms.py

class SomeForm(ModelForm):

checkbox = forms.BooleanField(required=False,
widget=forms.CheckboxInput(), label='some label')

def __init__(self, *args, **kw):
self.request = kw.pop('request')
super(SomeForm, self).__init__(*args, **kw)




On Apr 7, 10:19 am, Merrick <merr...@gmail.com> wrote:
> I appreciate all of the help, I was actually showing both Daniel and
> Raj that their suggestions have been tried to no result. To answer
> your question, look up at Raj's suggestion. My code before and after
> trying the suggestions above, is to have message defined outside of
> meta.
>
> Do you have a suggestion aside from that?
>
> Thanks.
>
> On Apr 7, 10:07 am, Tom Evans <tevans...@googlemail.com> wrote:
>
>
>
> > On Wed, Apr 7, 2010 at 5:30 PM, Merrick <merr...@gmail.com> wrote:
> > > Thank you.
>
> > > I'll be more specific, here is what I have:
>
> > > views.py
> > > -
> > > ...
> > > if request.method == 'POST':
> > >    some_form = SomeForm(data = request.POST, request=request,
> > > instance=somemodel)
> > >    ...
> > >    if some_form.is_valid():
> > >        some_form_update = some_form.save(commit=False)
> > >        if some_form.cleaned_data['checkbox']:
> > >            #do something
> > >            ...
> > >    return HttpResponseRedirect(reverse('app.views.somemodel_detail',
> > > args=(somemodel.key_id,)))
>
> > > else:
> > >    some_form = SomeForm(request=request, instance = somemodel)
>
> > >    return render_to_response("template.html", {'some_form':
> > > some_form}, context_instance=RequestContext(request))
>
> > > forms.py
> > > 
> > > class SomeForm(ModelForm):
>
> > >   def __init__(self, *args, **kw):
> > >        self.request = kw.pop('request')
> > >        super(SomeForm, self).__init__(*args, **kw)
>
> > >   #I originally had checkbox outside of meta but have tested both
> > > ways now
> > >   #checkbox = forms.BooleanField(required=False, label='Checkbox')
>
> > >    class Meta:
> > >        model = SomeModel
> > >        checkbox = forms.BooleanField(required=False,
> > > label='Checkbox')
>
> > This is wrong. Where did you see to put fields in a form in the Meta class?
>
> > class FooForm(forms.ModelForm):
> >   this_field_aint_on_the_model = forms.CharField(max_length=64)
> >   class Meta:
> >     model = Foo
>
> > 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-us...@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 add a field to a model form when the field is not in the model

2010-04-07 Thread Merrick
I appreciate all of the help, I was actually showing both Daniel and
Raj that their suggestions have been tried to no result. To answer
your question, look up at Raj's suggestion. My code before and after
trying the suggestions above, is to have message defined outside of
meta.

Do you have a suggestion aside from that?

Thanks.

On Apr 7, 10:07 am, Tom Evans <tevans...@googlemail.com> wrote:
> On Wed, Apr 7, 2010 at 5:30 PM, Merrick <merr...@gmail.com> wrote:
> > Thank you.
>
> > I'll be more specific, here is what I have:
>
> > views.py
> > -
> > ...
> > if request.method == 'POST':
> >    some_form = SomeForm(data = request.POST, request=request,
> > instance=somemodel)
> >    ...
> >    if some_form.is_valid():
> >        some_form_update = some_form.save(commit=False)
> >        if some_form.cleaned_data['checkbox']:
> >            #do something
> >            ...
> >    return HttpResponseRedirect(reverse('app.views.somemodel_detail',
> > args=(somemodel.key_id,)))
>
> > else:
> >    some_form = SomeForm(request=request, instance = somemodel)
>
> >    return render_to_response("template.html", {'some_form':
> > some_form}, context_instance=RequestContext(request))
>
> > forms.py
> > 
> > class SomeForm(ModelForm):
>
> >   def __init__(self, *args, **kw):
> >        self.request = kw.pop('request')
> >        super(SomeForm, self).__init__(*args, **kw)
>
> >   #I originally had checkbox outside of meta but have tested both
> > ways now
> >   #checkbox = forms.BooleanField(required=False, label='Checkbox')
>
> >    class Meta:
> >        model = SomeModel
> >        checkbox = forms.BooleanField(required=False,
> > label='Checkbox')
>
> This is wrong. Where did you see to put fields in a form in the Meta class?
>
> class FooForm(forms.ModelForm):
>   this_field_aint_on_the_model = forms.CharField(max_length=64)
>   class Meta:
>     model = Foo
>
> 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-us...@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 add a field to a model form when the field is not in the model

2010-04-07 Thread Merrick
Thank you.

I'll be more specific, here is what I have:

views.py
-
...
if request.method == 'POST':
some_form = SomeForm(data = request.POST, request=request,
instance=somemodel)
...
if some_form.is_valid():
some_form_update = some_form.save(commit=False)
if some_form.cleaned_data['checkbox']:
#do something
...
return HttpResponseRedirect(reverse('app.views.somemodel_detail',
args=(somemodel.key_id,)))

else:
some_form = SomeForm(request=request, instance = somemodel)

return render_to_response("template.html", {'some_form':
some_form}, context_instance=RequestContext(request))



forms.py

class SomeForm(ModelForm):

   def __init__(self, *args, **kw):
self.request = kw.pop('request')
super(SomeForm, self).__init__(*args, **kw)

   #I originally had checkbox outside of meta but have tested both
ways now
   #checkbox = forms.BooleanField(required=False, label='Checkbox')

class Meta:
model = SomeModel
checkbox = forms.BooleanField(required=False,
label='Checkbox')

On template.html I have to manually include the html for the message
input of type checkbox.

When I submit the form I get the error KeyError for the form field
"checkbox" that I manually added to template.html and debug points to
the line:

if some_form.cleaned_data['checkbox']:

Thanks again for helping.


On Apr 6, 11:46 pm, raj <rajeeshrn...@gmail.com> wrote:
> On Apr 7, 8:05 am, Merrick <merr...@gmail.com> wrote:
>
> > How should I go about adding a field to a model form
> > when the field is not part of the model?
>
>  Define a Custom ModelForm by specifying model in Meta and declare the
> required addnl field there.
> (check-box means boolean, right?). Now set form attribute of your
> Admin class with the name of YourForm.
>
> Rajeesh.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



how to add a field to a model form when the field is not in the model

2010-04-06 Thread Merrick
I added a checkbox form field to my template, and I even tried to add
it in my forms.py and then in my views.py I check for it like so:

if form.cleaned_data['checkbox_field']:
  code to send email...

But when I submit the form I get a KeyError. How should I go about
adding a field to a model form when the field is not part of the
model?

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-us...@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.



Restricting Access to Uploaded Files

2010-03-03 Thread Merrick
I wanted to give users who are authenticated the ability to upload
files, that's the easy part that I can handle.

What I cannot figure out is how to restrict the viewing/downloading of
files.

Links, tips, code are 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-us...@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: Efficient way to Display Comments with Threaded Replies

2010-03-02 Thread Merrick
I forgot to change out the name of the node to be path, which is what
it is. That's why I can sort on it.

Thank you, I'll give it a try.

On Mar 2, 12:04 am, Mihail Lukin <mihail.lu...@googlemail.com> wrote:
> I'm not sure what "node" is, but maybe you're looking for something
> like this:
>
> def comment_walk(comment, comment_list, level=0):
>     comment_list.append((comment, level))
>     for child in comment.children.all().order_by('node'):
>         comment_walk(child, comment_list, level+1)
>
> def post_view(request, post_id):
>     post = get_object_or_404(Post, pk=post_id)
>     level1 = post.comment_set.filter(parent=None).order_by('node')
>     comment_list = []
>     for comment in level1:
>         comment_walk(comment, comment_list)
>     return render_to_response('view_post.html', {'post': post,
> 'comment_list': comment_list})
>
> in "view_post.html" you'll be able to choose indentation by second
> item of the tuple, which is in the comment_list variable. I'm sorry if
> there are errors, I didn't validate that code, this is just an idea.
>
> On 2 ÍÁÒ, 09:53, Merrick <merr...@gmail.com> wrote:
>
> > I have a comments model that is setup to do threaded replies. I am
> > having trouble figuring out how to display the comments in a threaded
> > manner, i.e. tree.
>
> > My model looks like this:
>
> > class Comment(models.Model):
> > š š post = šmodels.ForeignKey(Post, null=True, blank=True)
> > š š user = models.ForeignKey(User, null=True, blank=True)
> > š š comment = models.TextField(null=True, blank=True)
> > š š parent = models.ForeignKey('self', null=True, blank=True,
> > default=None,
> > š š š š related_name='children')
> > š š node = models.CharField(null=True, blank=True, default=None,
> > max_length=1024)
> > š š created = models.DateTimeField(auto_now_add=True, editable=False)
>
> > When I sort by node, I get the correct order of comments.
>
> > I was hoping someone has an idea of how to iterate through the
> > comments for a particular post, and have them appear as a tree.
>
> > 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-us...@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.



Efficient way to Display Comments with Threaded Replies

2010-03-01 Thread Merrick
I have a comments model that is setup to do threaded replies. I am
having trouble figuring out how to display the comments in a threaded
manner, i.e. tree.

My model looks like this:

class Comment(models.Model):
post =  models.ForeignKey(Post, null=True, blank=True)
user = models.ForeignKey(User, null=True, blank=True)
comment = models.TextField(null=True, blank=True)
parent = models.ForeignKey('self', null=True, blank=True,
default=None,
related_name='children')
node = models.CharField(null=True, blank=True, default=None,
max_length=1024)
created = models.DateTimeField(auto_now_add=True, editable=False)

When I sort by node, I get the correct order of comments.

I was hoping someone has an idea of how to iterate through the
comments for a particular post, and have them appear as a tree.

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-us...@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: Separate a project into 2 - both need to access the same models

2009-09-16 Thread Merrick

Got it thanks, I'll try it out.

On Sep 15, 11:47 pm, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Sep 16, 6:45 am, Merrick <merr...@gmail.com> wrote:
>
>
>
> > I have a project that I am thinking of breaking up into 2 sites/
> > projects. The goal is to be able to make changes to one site/project
> > without affecting the other one. Here is an example of what each would
> > do:
>
> > mydomain.com
> > -
> > - displays the brochure website (sales copy on the homepage, about,
> > privacy etc...) (Page Model)
> > - tracks visitors as they move around from one Page to another (Access
> > Model)
>
> > dashboard.mydomain.com
> > 
> > - users can login
> > - user can click on a Page and see how many times it was Accessed
> > (Page and Access model)
>
> > So I am operating under the assumption that I will have a total of 2
> > settings files, one for each site/project. I am guessing that I need
> > to define the models Page and Access model on each project. Is this
> > correct? Is there an optimal way of splitting things up to keep up
> > time up, but avoiding repeating model definitions?
>
> > Thanks.
>
> 'Project' is a bit of an artificial concept. The only thing a Django
> site really needs is a settings.py. So you can have two of these, with
> separate Apache vhosts or whatever, but with both referring to the
> same models files - as long as those models are on the Python path.
> --
> DR.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Separate a project into 2 - both need to access the same models

2009-09-15 Thread Merrick

I have a project that I am thinking of breaking up into 2 sites/
projects. The goal is to be able to make changes to one site/project
without affecting the other one. Here is an example of what each would
do:

mydomain.com
-
- displays the brochure website (sales copy on the homepage, about,
privacy etc...) (Page Model)
- tracks visitors as they move around from one Page to another (Access
Model)

dashboard.mydomain.com

- users can login
- user can click on a Page and see how many times it was Accessed
(Page and Access model)

So I am operating under the assumption that I will have a total of 2
settings files, one for each site/project. I am guessing that I need
to define the models Page and Access model on each project. Is this
correct? Is there an optimal way of splitting things up to keep up
time up, but avoiding repeating model definitions?

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
-~--~~~~--~~--~--~---



Re: Modify the value in a row before returning through a query

2009-08-24 Thread Merrick

Another thread today just clued me in. Adding @property to the model
method made it work. Thank you for helping out Javier, I provided the
full example below in case someone else looks for this:

import urlparse

def stripdomain(url):
bits = urlparse.urlparse(url)
return bits[1]

class yourmodel (models.Model):
  
  domain = models.URLField(...)
  
  @property
  def strippeddomain (self):
 return stripdomain(self.domain)

Then from the shell this works:

>>> url = yourmodel.objects.get(id=1)
>>> url.strippeddomain
u'yourdomain.com'



On Aug 24, 3:37 pm, Merrick <merr...@gmail.com> wrote:
> url.stripdomain() returns:
>
> yourdomain.com
>
> Do you know if there is a way to have url.domain return what
> stripdomain() did above? Otherwise I'll use a template filter and move
> on.
>
> Merrick
>
> On Aug 24, 12:20 pm, Javier Guerra <jav...@guerrag.com> wrote:
>
> > On Mon, Aug 24, 2009 at 1:42 PM, Merrick<merr...@gmail.com> wrote:
> > >>>> url = yourmodel.objects.get(id=1)
> > >>>> url.domain
> > > u'http://yourdomain.com/'
>
> > what does url.stripdomain() return?
>
> > --
> > Javier
>
>
--~--~-~--~~~---~--~~
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: Modify the value in a row before returning through a query

2009-08-24 Thread Merrick

Looks like we were writing at the same time. I also was not aware you
could call a model method in a template without the parenthesis,
that's where I was getting hung up.

Again thank you.

On Aug 24, 3:54 pm, Javier Guerra <jav...@guerrag.com> wrote:
> On Mon, Aug 24, 2009 at 5:37 PM, Merrick<merr...@gmail.com> wrote:
> > Do you know if there is a way to have url.domain return what
> > stripdomain() did above? Otherwise I'll use a template filter and move
> > on.
>
> no need for a filter, {{url.stripdomain}} will call url.stripdomain()
>
> or, you could set url.stripdomain() as a property:
>
> class ..:
>   ...
>   @property
>   def stripdomain(self):
>     .
>
> --
> Javier
--~--~-~--~~~---~--~~
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: Modify the value in a row before returning through a query

2009-08-24 Thread Merrick

url.stripdomain() returns:

yourdomain.com

Do you know if there is a way to have url.domain return what
stripdomain() did above? Otherwise I'll use a template filter and move
on.

Merrick


On Aug 24, 12:20 pm, Javier Guerra <jav...@guerrag.com> wrote:
> On Mon, Aug 24, 2009 at 1:42 PM, Merrick<merr...@gmail.com> wrote:
> >>>> url = yourmodel.objects.get(id=1)
> >>>> url.domain
> > u'http://yourdomain.com/'
>
> what does url.stripdomain() return?
>
> --
> Javier
--~--~-~--~~~---~--~~
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: Modify the value in a row before returning through a query

2009-08-24 Thread Merrick

Thank you Javier, for some reason I cannot get it working.

Using your example, I noticed the return value is stripdomain, I am
assuming that function would be outside of the model?

Assuming the code you provided, I would expect that adding the code
below, directly above the class yourmodel definition, would work:

import urlparse

def stripdomain(url):
bits = urlparse.urlparse(url)
return bits[1]

However the domain is not stripped when querying as follows:

>>> url = yourmodel.objects.get(id=1)
>>> url.domain
u'http://yourdomain.com/'

Can you tell if I am missing something?


On Aug 24, 11:05 am, Javier Guerra <jav...@guerrag.com> wrote:
> On Mon, Aug 24, 2009 at 1:01 PM, Merrick<merr...@gmail.com> wrote:
> > I know how to parse the URL but am drawing a blank on how to
> > accomplish this at the model level.
>
> add a function to the model, that returns the parsed field.
>
> class yourmodel (models.Model):
>   
>   domain = models.URLField(...)
>   
>   def strippeddoamin (self):
>      return stripdomain(self.domain)
>
> --
> Javier
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Modify the value in a row before returning through a query

2009-08-24 Thread Merrick

I have this in models.py:

domain = models.URLField(...)

Let's say one row in the table has this for domain:

'http://www.google.com'

 When the domain field is looked up, I would like to return:

www.google.com

I know how to parse the URL but am drawing a blank on how to
accomplish this at the model level.
--~--~-~--~~~---~--~~
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: proper way to use S3Storage and Django ImageField

2009-01-19 Thread Merrick

I am using S3Storage with an imagefield successfully. It sounds like
you have not specified the storage engine and keys etc... in
settings.py as creecode pointed out.

I recall testing that the directory will be created on the fly if it
does not exist.

On Jan 19, 12:40 pm, creecode  wrote:
> Hello Aaron,
>
> I can confirm that it can work.  I'm using it but I don't know enough
> to diagnose your problem.
>
> Have you created the userprofile "directory" in your S3 bucket?
>
> Have you added the following to your settings.py?
>
> DEFAULT_FILE_STORAGE = 'S3Storage.S3Storage'
>
> AWS_ACCESS_KEY_ID
> AWS_SECRET_ACCESS_KEY
> AWS_STORAGE_BUCKET_NAME
> AWS_CALLING_FORMAT
>
> Have you installed any software S3Storage depends on?
>
> On Jan 19, 8:02 am, "Aaron Lee"  wrote:
>
> > So I guess S3Storage doesn't work with ImageField? Can anyone confirm that?
>
> Toodle-l.
> creecode
--~--~-~--~~~---~--~~
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: S3Storage.py and Thumbnails using PIL (IOError / cannot identify image file)

2008-12-22 Thread Merrick

I am always amazed by the support here, thank you.

After seeing Brian's code I switched resize_image() to be a model
method and then I switched from saving the form to saving the profile

profile = request.user.get_profile()
profile.save_picture(pform.cleaned_data['picture'].read())

instead of

new_profile = pform.save(commit=False)
new_profile.picture.save(filename, thumbnail_content)

Merrick

On Dec 22, 1:10 pm, brianmac44 <anon1...@gmail.com> wrote:
> With my code, what are you using as "content"?
>
> I'm using: form.cleaned_data['source'].read()
>
> So my code looks something like this:
> PHOTO_MEDIUM_SIZE = 400,400
> source_image = form.cleaned_data['source'].read()
> resized_image = resize_photo(source_image,PHOTO_MEDIUM_SIZE))
> photos.save(image_name,resized_image)
>
> You may want to also want to  check the image file you are using for
> testing, interlaced PNG's are not supported by 
> PIL.http://www.pythonware.com/library/pil/handbook/format-png.htm
>
> -Brian
>
> On Dec 22, 2:46 pm,Merrick<merr...@gmail.com> wrote:
>
> > I got the same result with brianmac44's code. I also verified that the
> > my resize_image() works when opening the file from the local
> > filesystem - so I am somehow not passing the file in a manner that
> > Image.open likes.
>
> > On Dec 22, 4:45 am, brianmac44 <anon1...@gmail.com> wrote:
>
> > > I had the same problem two weeks ago. This is what I wrote:
>
> > > def resize_photo(self,content,size):
> > >     img = Image.open(ContentFile(content))
> > >     img.thumbnail(size, Image.ANTIALIAS)
> > >     io = StringIO.StringIO()
> > >     img.save(io, 'PNG')
> > >     return ContentFile(io.getvalue())
>
> > > Hope this helps.
>
> > > -Brian
>
> > > On Dec 22, 4:41 am,Merrick<merr...@gmail.com> wrote:
>
> > > > Thank you I tried that and I still get the same error.
>
> > > > I spent a little more time looking at PIL / Image.py and cleaning up
> > > > the code. From what I can tell the Image.open method is having trouble
> > > > with what I am passing to it.
>
> > > > def resize_image(file, size=(50, 50)):
> > > >     from PIL import Image
> > > >     from cStringIO import StringIO
> > > >     from django.core.files.base import ContentFile
>
> > > >     image_data = StringIO(file.read())
>
> > > >     ### this line below is where the issue is ###
> > > >     image = Image.open(image_data)
>
> > > >     if image.mode not in ('L', 'RGB'):
> > > >         image = image.convert('RGB')
> > > >     image.thumbnail(size, Image.ANTIALIAS)
> > > >     o = StringIO()
> > > >     image.save(o, "JPEG")
> > > >     return  ContentFile(o.getvalue())
>
> > > > This is how I call it:
> > > >             picture = pform.cleaned_data['picture']
> > > >             thumbnail_content = resize_image(picture)
>
> > > > Thank you for looking at this.
>
> > > > On Dec 21, 3:08 pm, "j...@zigzap.com" <jlb2...@gmail.com> wrote:
>
> > > > > From what I can tell your not wrapping the thumbnailfilein
> > > > > ContentFile your just returning the rawfilefrom the string IO.  To
> > > > > use the the ImageField django provides you must provide it with afile
> > > > > that is in a special wrapper called ContentFile.  I would suggest
> > > > > trying this:
>
> > > > > from django.core.files.base import ContentFile   (import this function
> > > > > at the top of your view or where ever you put def resize_image)
>
> > > > > change the last line of def resize_image from "return o.getvalue()" to
> > > > > "return ContentFile(o.getvalue())"
>
> > > > > I would also recommend changing "new_profile.picture.save(filename,
> > > > > thumbnail_content)" to "new_profile.picture.save(filename,
> > > > > thumbnail_content, save=False)" so that you are not hitting the
> > > > > database twice.
--~--~-~--~~~---~--~~
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: S3Storage.py and Thumbnails using PIL (IOError / cannot identify image file)

2008-12-22 Thread Merrick

I got the same result with brianmac44's code. I also verified that the
my resize_image() works when opening the file from the local
filesystem - so I am somehow not passing the file in a manner that
Image.open likes.

On Dec 22, 4:45 am, brianmac44 <anon1...@gmail.com> wrote:
> I had the same problem two weeks ago. This is what I wrote:
>
> def resize_photo(self,content,size):
>     img = Image.open(ContentFile(content))
>     img.thumbnail(size, Image.ANTIALIAS)
>     io = StringIO.StringIO()
>     img.save(io, 'PNG')
>     return ContentFile(io.getvalue())
>
> Hope this helps.
>
> -Brian
>
> On Dec 22, 4:41 am, Merrick <merr...@gmail.com> wrote:
>
> > Thank you I tried that and I still get the same error.
>
> > I spent a little more time looking at PIL / Image.py and cleaning up
> > the code. From what I can tell the Image.open method is having trouble
> > with what I am passing to it.
>
> > def resize_image(file, size=(50, 50)):
> >     from PIL import Image
> >     from cStringIO import StringIO
> >     from django.core.files.base import ContentFile
>
> >     image_data = StringIO(file.read())
>
> >     ### this line below is where the issue is ###
> >     image = Image.open(image_data)
>
> >     if image.mode not in ('L', 'RGB'):
> >         image = image.convert('RGB')
> >     image.thumbnail(size, Image.ANTIALIAS)
> >     o = StringIO()
> >     image.save(o, "JPEG")
> >     return  ContentFile(o.getvalue())
>
> > This is how I call it:
> >             picture = pform.cleaned_data['picture']
> >             thumbnail_content = resize_image(picture)
>
> > Thank you for looking at this.
>
> > On Dec 21, 3:08 pm, "j...@zigzap.com" <jlb2...@gmail.com> wrote:
>
> > > From what I can tell your not wrapping the thumbnailfilein
> > > ContentFile your just returning the rawfilefrom the string IO.  To
> > > use the the ImageField django provides you must provide it with afile
> > > that is in a special wrapper called ContentFile.  I would suggest
> > > trying this:
>
> > > from django.core.files.base import ContentFile   (import this function
> > > at the top of your view or where ever you put def resize_image)
>
> > > change the last line of def resize_image from "return o.getvalue()" to
> > > "return ContentFile(o.getvalue())"
>
> > > I would also recommend changing "new_profile.picture.save(filename,
> > > thumbnail_content)" to "new_profile.picture.save(filename,
> > > thumbnail_content, save=False)" so that you are not hitting the
> > > database twice.
--~--~-~--~~~---~--~~
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: S3Storage.py and Thumbnails using PIL (IOError / cannot identify image file)

2008-12-22 Thread Merrick

Thank you I tried that and I still get the same error.

I spent a little more time looking at PIL / Image.py and cleaning up
the code. From what I can tell the Image.open method is having trouble
with what I am passing to it.

def resize_image(file, size=(50, 50)):
from PIL import Image
from cStringIO import StringIO
from django.core.files.base import ContentFile

image_data = StringIO(file.read())

### this line below is where the issue is ###
image = Image.open(image_data)

if image.mode not in ('L', 'RGB'):
image = image.convert('RGB')
image.thumbnail(size, Image.ANTIALIAS)
o = StringIO()
image.save(o, "JPEG")
return  ContentFile(o.getvalue())


This is how I call it:
picture = pform.cleaned_data['picture']
thumbnail_content = resize_image(picture)

Thank you for looking at this.

On Dec 21, 3:08 pm, "j...@zigzap.com"  wrote:
> From what I can tell your not wrapping the thumbnailfilein
> ContentFile your just returning the rawfilefrom the string IO.  To
> use the the ImageField django provides you must provide it with afile
> that is in a special wrapper called ContentFile.  I would suggest
> trying this:
>
> from django.core.files.base import ContentFile   (import this function
> at the top of your view or where ever you put def resize_image)
>
> change the last line of def resize_image from "return o.getvalue()" to
> "return ContentFile(o.getvalue())"
>
> I would also recommend changing "new_profile.picture.save(filename,
> thumbnail_content)" to "new_profile.picture.save(filename,
> thumbnail_content, save=False)" so that you are not hitting the
> database twice.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



S3Storage.py and Thumbnails using PIL (IOError / cannot identify image file)

2008-12-19 Thread Merrick

I setup S3Storage as my default storage and can successfully upload
images to S3 without overriding save on my profile_update below. Right
now, when I submit a form with an image I get the original image
uploaded in my S3 bucket not a thumbnail and an IO Error - "cannot
identify image file" - traceback all the way down. I know its
complicated but I have to imagine other people will attempt to create
a thumbnail in memory and upload to S3 without saving locally. Thank
you for helping.

models.py

class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
picture = models.ImageField(upload_to='profiles', null=True,
blank=True)

views.py
===
def resize_image(buf, size=(100, 100)):
import Image as PILImage
import cStringIO
f = cStringIO.StringIO(buf)
image = PILImage.open(f)
if image.mode not in ('L', 'RGB'):
image = image.convert('RGB')
image.thumbnail(size, PILImage.ANTIALIAS)
o = cStringIO.StringIO()
image.save(o, "JPEG")
return o.getvalue()

@login_required(redirect_field_name='redirect_to')
def profile_update(request):
profile = request.user.get_profile()
...

if request.method == 'POST':
 pform = ProfileForm(request.POST, request.FILES,
instance=profile)
else:
 pform = ProfileForm(instance=profile)

if pform.is_valid()
new_profile = pform.save(commit=False)
if(pform.cleaned_data['picture']):

raw_image_data = pform.cleaned_data['picture'].read()
thumbnail_content = resize_image(raw_image_data)
filename = pform.cleaned_data['picture'].name
filename = os.path.splitext(filename)[0] + ".jpg"
new_profile.picture.save(filename, thumbnail_content)

new_profile.save()


traceback
===
IOError at /profile/update
cannot identify image file

Traceback:
File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py"
in get_response
  86. response = callback(request, *callback_args,
**callback_kwargs)
File "/usr/lib/python2.4/site-packages/django/contrib/auth/
decorators.py" in __call__
  67. return self.view_func(request, *args, **kwargs)
File "/var/mysite/views.py" in profile_update
  705. thumbnail_content = resize_image
(raw_image_data)
File "/var/mysite/views.py" in resize_image
  677. image = PILImage.open(f)
File "/usr/lib/python2.4/site-packages/PIL/Image.py" in open
  1745. raise IOError("cannot identify image file")

Exception Type: IOError at /profile/update
Exception Value: cannot identify image file


--~--~-~--~~~---~--~~
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: Update Values to Null

2008-11-17 Thread Merrick

But of course! Thank you.

On Nov 17, 8:25 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Mon, Nov 17, 2008 at 9:06 PM, Merrick <[EMAIL PROTECTED]> wrote:
>
> > I cannot figure out how to update a foreign key to a null value.
> > Thanks.
>
> > models.py
> > 
> > group = models.ForeignKey(group, null=True, blank=True)
>
> > >>> from redirect.models import *
> > >>> Links = Link.objects.filter(group = 6)
> > >>> Links.update(group = NULL)
>
> > Traceback (most recent call last):
> >  File "", line 1, in ?
> > NameError: name 'NULL' is not defined
>
> > >>> Links.update(group = 'NULL')
> > ...
> > ProgrammingError: invalid input syntax for integer: "NULL"
>
> Try None instead of NULL.
>
> Karen
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Update Values to Null

2008-11-17 Thread Merrick

I cannot figure out how to update a foreign key to a null value.
Thanks.

models.py

group = models.ForeignKey(group, null=True, blank=True)

>>> from redirect.models import *
>>> Links = Link.objects.filter(group = 6)
>>> Links.update(group = NULL)

Traceback (most recent call last):
  File "", line 1, in ?
NameError: name 'NULL' is not defined

>>> Links.update(group = 'NULL')
...
ProgrammingError: invalid input syntax for integer: "NULL"


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: avoid cascade delete

2008-11-17 Thread Merrick

Thank you for all of the advice, it is nice to have so many options. I
ended up using:

group.link_set.clear()
group.delete()

On Nov 17, 7:57 am, "David Zhou" <[EMAIL PROTECTED]> wrote:
> On Mon, Nov 17, 2008 at 10:46 AM, Randy Barlow <[EMAIL PROTECTED]> wrote:
>
> > On Sun, 16 Nov 2008 23:21:05 -0800 (PST), Merrick <[EMAIL PROTECTED]>
> > declared:
> >> I have two models, links and groups. A Link has an optional foreign
> >> key Group.
>
> >> When I delete a Group, Django by default deletes all Links that
> >> referenced the Group that is being deleted.
>
> >> How do I avoid the default behavior that does a cascade delete. Of
> >> course I could use the cursor but would am hoping there is some option
> >> I don't know of for delete().
>
> > I would argue this is more desireable than using clear() explicitly,
> > because you don't have to know anything about your models with this
> > method.  Any time you have to remember to set a certain
> > relationship to null, you are bound to forget about another
> > relationship between your objects, and you'll get cascading delete on
> > something you didn't expect, and you won't have even noticed that it
> > happened!
>
> But that just means you'll need to explicitly set cascade on those
> models you *do* want to cascade delete.  And, IMO, the vast majority
> of foreign key use cases do benefit from an auto cascading delete.
>
> For the specific Links/Groups example, personally I'd just do it with
> a many to many relation.  It's entirely feasible that in the future,
> Links will need the ability to associate itself to multiple groups.
> For now, I'd just limit a link to one group via some custom
> validation.
>
> --
> ---
> David Zhou
> [EMAIL PROTECTED]
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



avoid cascade delete

2008-11-16 Thread Merrick

I have two models, links and groups. A Link has an optional foreign
key Group.

When I delete a Group, Django by default deletes all Links that
referenced the Group that is being deleted.

How do I avoid the default behavior that does a cascade delete. Of
course I could use the cursor but would am hoping there is some option
I don't know of for delete().
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



access request.user in class Meta

2008-11-01 Thread Merrick

I am trying to dynamically generate a form, the fields will vary if
the user is logged in. Here is where I am so far

forms.py
==
class LinkForm(ModelForm):

def __init__(self, *args, **kw):
self.request = kw.pop('request')
super(LinkForm, self).__init__(*args, **kw)

class Meta:
model = Link
if self.request.user:
exclude = ['ip_address', 'timestamp', 'user', 'method', ]
else:
exclude = ['ip_address', 'timestamp', 'user', 'method',
'notes', 'private_stats',]

views.py
==
def index(request):
form = LinkForm(request=request)

The error I get makes it clear I don't have access to request within
class Meta:

NameError at /
name 'self' is not defined

Thanks,

Merrick

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



access request.user in clean method of ModelForm

2008-10-31 Thread Merrick

How can I access request.user in a clean method of a ModelForm?

I have the following code in forms.py:

===
#profle email form
class UserEmailForm(ModelForm):
class Meta:
model = User
fields = ['email',]

def clean_email(self):
email_submitted = self.cleaned_data.get('email')
email_exists =
User.objects.filter(email=email_submitted).exclude(username=request.user.username).count()

if email_exists:
raise forms.ValidationError('That email address is in
use')
else:
return email
===

When I attempt to pull up the form, I get this error:

===
NameError at /profile/update

global name 'request' is not defined

Request Method: POST
Request URL:http://dev.twiturl.com/profile/update
Exception Type: NameError
Exception Value:

global name 'request' is not defined
===

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Access request.user in a clean method of a ModelForm

2008-10-31 Thread Merrick

I have the code below:
===
class UserEmailForm(ModelForm):
class Meta:
model = User
fields = ['email',]

def clean_email(self):
email_submitted = self.cleaned_data.get('email')
email_exists =
User.objects.filter(email=email_submitted).exclude(username=request.user.username).count()

if email_exists:
raise forms.ValidationError('That email address is in
use')
else:
return email
===

And when I try to request the form with my browser I get the following
error:

===
NameError at /profile/update

global name 'request' is not defined

Request Method: POST
Request URL:http://mydomain.com/profile/update
Exception Type: NameError
Exception Value:

global name 'request' is not defined

Exception Location: /var/virtualhosts/twiturl_com/redirect/forms.py
in clean_email, line 18
===

How do I access request.user in the clean_email method of the
UserEmailForm ModelForm?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Plot Location of IP Addresses on a Google Map

2008-10-11 Thread Merrick

I think it might be overkill to use GeoDjango, anyone else know of a
module I can use for this?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Double encoded slash in path_info removed when using apache/wsgi

2008-10-09 Thread Merrick

Thank you Graham, I was going crazy trying to figure this out.

Thankfully I control my hosting environment top to bottom (colocation)
so I will try using REQUEST_URI I will use it.


On Oct 8, 3:00 am, Graham Dumpleton <[EMAIL PROTECTED]>
wrote:
> On Oct 8, 5:57 pm, Merrick <[EMAIL PROTECTED]> wrote:
>
> > Could this problem be in the wsgi.py handler in django? If not I
> > suppose I need to look at mod_wsgi and quit asking here :)
>
> It is how Apache works and there is possibly not much you can do about
> it.
>
> In Apache 1.3, repeatingslashescan be passed through to CGI
> PATH_INFO variable in certain situations, but in Apache 2.X they
> aren't and instead, repeatingslashesare collapsed by Apache.
>
> To make the behaviour consistent, mod_wsgi will apply Apache 2.X
> behaviour to Apache 1.3 when passing through CGI variables in WSGI
> environment, and will drop repeatingslashes.
>
> So, if using Apache 2.X there would be nothing that could be done even
> if mod_wsgi code weren't collapsing the repeatingslashes.
>
> The closest you will get would be to look at and parse value of
> REQUEST_URI variable passed through in WSGI environment. For example,
> for normal and encoding repeatingslashes, one gets:
>
> PATH_INFO: '/a/b/c/http:/www.wired.com/'
> QUERY_STRING: ''
> REQUEST_URI: '/wsgi/scripts/echo.py/a//b/c/http%3A%2F%2Fwww.wired.com
> %2F%2F'
> SCRIPT_NAME: '/wsgi/scripts/echo.py'
>
> Although Apache/mod_wsgi supplies REQUEST_URI, it isn't a required
> WSGI variable and may not be available with other WSGI hosting
> solutions.
>
> In general relying onslashesand/or encodedslashesin PATH_INFO may
> not be a good idea. For discussion on these issues read through:
>
>  http://groups.google.com/group/python-web-sig/browse_frm/thread/2003e...
>  http://groups.google.com/group/python-web-sig/browse_frm/thread/5907c...
>
> Graham
>
> > On Oct 7, 4:05 pm, Merrick <[EMAIL PROTECTED]> wrote:
>
> > > I need urls that contain other urls within them i.e.
>
> > >http://mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F%2F
>
> > > I am using Apache 2.2.3-4, mod_wsgi 2.0-1 and have
> > > "AllowEncodedSlashes On" within my virtualhost conf file, this setting
> > > allows me to have encodedslashesin the path_info without having
> > > apache return a fake 404.
>
> > > My views.py includes:
>
> > > def find(request, url):
> > >     import urllib
> > >     url = urllib.unquote_plus(url)
> > >     form = FindForm({'url': url,})
> > >     return render_to_response('find.html', { 'form': form, 'request':
> > > request })
>
> > > The template find.html includes a line {{ request.path_info }} to
> > > print out the path_info.
>
> > > Firefox shows the second encoded forward slash is removed when calling
> > > this url:http://mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F%2F
> > >  prints out:
> > > /find/http:/www.wired.com/
>
> > > The django test client prints out the second forward slash
>
> > > >>> ./manage.py
> > > >>> from django.test.client import Client
> > > >>> c = Client()
> > > >>> response = c.get('/bookmarklet/http:%2F%2Fwww.wired.com%2F%2F')
> > > >>> response.content
>
> > > '/find/http://www.wired.com//'
>
> > > I did not include anything about my regular expression in urls.py up
> > > until this point because it is not related to this problem from what I
> > > can tell, but in case you are wondering I was trying to capture the
> > > url after find/ - my regex looks like this r'^find/(?P(.*))$'
>
> > > Thanks for looking at this,
>
> > > Merrick
>
>
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Double encoded slash in path_info removed when using apache/wsgi

2008-10-08 Thread Merrick

Could this problem be in the wsgi.py handler in django? If not I
suppose I need to look at mod_wsgi and quit asking here :)


On Oct 7, 4:05 pm, Merrick <[EMAIL PROTECTED]> wrote:
> I need urls that contain other urls within them i.e.
>
> http://mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F%2F
>
> I am using Apache 2.2.3-4, mod_wsgi 2.0-1 and have
> "AllowEncodedSlashes On" within my virtualhost conf file, this setting
> allows me to have encoded slashes in the path_info without having
> apache return a fake 404.
>
> My views.py includes:
>
> def find(request, url):
>     import urllib
>     url = urllib.unquote_plus(url)
>     form = FindForm({'url': url,})
>     return render_to_response('find.html', { 'form': form, 'request':
> request })
>
> The template find.html includes a line {{ request.path_info }} to
> print out the path_info.
>
> Firefox shows the second encoded forward slash is removed when calling
> this url:http://mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F%2F
>  prints out:
> /find/http:/www.wired.com/
>
> The django test client prints out the second forward slash
>
> >>> ./manage.py
> >>> from django.test.client import Client
> >>> c = Client()
> >>> response = c.get('/bookmarklet/http:%2F%2Fwww.wired.com%2F%2F')
> >>> response.content
>
> '/find/http://www.wired.com//'
>
> I did not include anything about my regular expression in urls.py up
> until this point because it is not related to this problem from what I
> can tell, but in case you are wondering I was trying to capture the
> url after find/ - my regex looks like this r'^find/(?P(.*))$'
>
> Thanks for looking at this,
>
> Merrick
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Double encoded slash in path_info removed when using apache/wsgi

2008-10-07 Thread Merrick

I need urls that contain other urls within them i.e.

http://mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F%2F

I am using Apache 2.2.3-4, mod_wsgi 2.0-1 and have
"AllowEncodedSlashes On" within my virtualhost conf file, this setting
allows me to have encoded slashes in the path_info without having
apache return a fake 404.

My views.py includes:

def find(request, url):
import urllib
url = urllib.unquote_plus(url)
form = FindForm({'url': url,})
return render_to_response('find.html', { 'form': form, 'request':
request })


The template find.html includes a line {{ request.path_info }} to
print out the path_info.

Firefox shows the second encoded forward slash is removed when calling
this url:
http://mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F%2F
 prints out:
/find/http:/www.wired.com/

The django test client prints out the second forward slash

>>> ./manage.py
>>> from django.test.client import Client
>>> c = Client()
>>> response = c.get('/bookmarklet/http:%2F%2Fwww.wired.com%2F%2F')
>>> response.content
'/find/http://www.wired.com//'

I did not include anything about my regular expression in urls.py up
until this point because it is not related to this problem from what I
can tell, but in case you are wondering I was trying to capture the
url after find/ - my regex looks like this r'^find/(?P(.*))$'

Thanks for looking at this,

Merrick
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Regex pattern for URL matching

2008-10-06 Thread Merrick

I think this is related to WSGI.

On Oct 6, 7:17 pm, Merrick <[EMAIL PROTECTED]> wrote:
> That is the approach I took and how I resolved the original problem
> with the 404. It led me to find that "AllowEncodedSlashes On" in
> Apache is needed for encoded slashes to be allowed in the pathname
> information following the filename.
>
> The problem now is that
>
> http%3A%2F%2F prints http:/ in my template,
>
> http%3A%2F also prints out as http:/
>
> The second encoded forward slash is being omitted.
>
> http%3A%2F$2Fwww.wired.com%2Fprints http:/www.wired.com/
>
> http%3A%2F$2Fwww.wired.com%2F%2Falso prints http:/www.wired.com/
>
> Thanks for looking at this.
>
> On Oct 6, 5:56 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
> wrote:
>
> > On Mon, 2008-10-06 at 16:10 -0700, Merrick wrote:
> > > keith, thanks for trying.
>
> > > %2f is the encoded value of /, but urls contain other characters as
> > > well not just alphanumeric.
>
> > I think you're debugging the wrong piece of the problem here. Your
> > original regular expression must have been pretty close to the right
> > answer, although since it wasn't a valid reg-exp (mis-matched
> > parentheses, it's hard to tell). Using "." to match "any character" was
> > the right approach.
>
> > I would start debugging this by trying a simpler example. You said the
> > pattern matched "www.wired.com" and then leapt straight to "http%3A%2F%
> > 2Fwww.wired.com%2F". So what about something in between, say "%3A" or
> > just "www.wored.com%2F".
>
> > Also, where do things fail? Does the regular expression not match
> > anything or does the view not finish for some reason (i.e. do you know
> > for sure that the view isn't being called)? Because, again, your
> > original regular expression, once you fix the syntax error, looks like
> > it should work correctly.
>
> > Go back to the start, fix the error with the missing parenthese, start
> > from something you know works and then add one character at a time until
> > it fails. Put debugging prints in your view so that you know if the view
> > gets called or not.
>
> > Regards,
> > Malcolm
>
>
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Regex pattern for URL matching

2008-10-06 Thread Merrick

That is the approach I took and how I resolved the original problem
with the 404. It led me to find that "AllowEncodedSlashes On" in
Apache is needed for encoded slashes to be allowed in the pathname
information following the filename.

The problem now is that

http%3A%2F%2F prints http:/ in my template,

http%3A%2F also prints out as http:/

The second encoded forward slash is being omitted.

http%3A%2F$2Fwww.wired.com%2F prints http:/www.wired.com/

http%3A%2F$2Fwww.wired.com%2F%2F also prints http:/www.wired.com/

Thanks for looking at this.


On Oct 6, 5:56 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Mon, 2008-10-06 at 16:10 -0700, Merrick wrote:
> > keith, thanks for trying.
>
> > %2f is the encoded value of /, but urls contain other characters as
> > well not just alphanumeric.
>
> I think you're debugging the wrong piece of the problem here. Your
> original regular expression must have been pretty close to the right
> answer, although since it wasn't a valid reg-exp (mis-matched
> parentheses, it's hard to tell). Using "." to match "any character" was
> the right approach.
>
> I would start debugging this by trying a simpler example. You said the
> pattern matched "www.wired.com" and then leapt straight to "http%3A%2F%
> 2Fwww.wired.com%2F". So what about something in between, say "%3A" or
> just "www.wored.com%2F".
>
> Also, where do things fail? Does the regular expression not match
> anything or does the view not finish for some reason (i.e. do you know
> for sure that the view isn't being called)? Because, again, your
> original regular expression, once you fix the syntax error, looks like
> it should work correctly.
>
> Go back to the start, fix the error with the missing parenthese, start
> from something you know works and then add one character at a time until
> it fails. Put debugging prints in your view so that you know if the view
> gets called or not.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Regex pattern for URL matching

2008-10-06 Thread Merrick

While I have not found the complete solution, I am closer. I added
this to my apache settings for the virtual host:

AllowEncodedSlashes On

I am no longer getting a 404. But even though the url has two
instances of %2f to represent two slashes:

http://mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F

I am able to capture the URL, but with only one slash. I pass it to my
ModelForm and it prints in my template as:

http:/www.wired.com/

Note the lack of double forward slashes after the colon.




On Oct 6, 4:10 pm, Merrick <[EMAIL PROTECTED]> wrote:
> keith, thanks for trying.
>
> %2f is the encoded value of /, but urls contain other characters as
> well not just alphanumeric.
>
> I suspect this issue may have to do with apache or WSGI but not sure
> what.
>
> On Oct 6, 4:06 pm, "Keith Eberle" <[EMAIL PROTECTED]> wrote:
>
> > quick solution, i think you could add the % to the regex  (i'm hardly a
> > regex master):
>
> > r'^find/(?P[%-\w]+)$
>
> > keith
>
> > On Mon, Oct 6, 2008 at 7:05 PM, Merrick <[EMAIL PROTECTED]> wrote:
>
> > > I have narrowed down the problem to %2F in my url, anyone?
>
> > > On Oct 6, 2:55 pm, Merrick <[EMAIL PROTECTED]> wrote:
> > > > \w will only match alphanumeric characters, I need to match anything
> > > > and will let my modelform verify that it is indeed a URL.
>
> > > > On Oct 6, 2:43 pm, Merrick <[EMAIL PROTECTED]> wrote:
>
> > > > > Thank you, I meant urls.py. APPEND_SLASH = False so I omitted the
> > > > > trailing slash from the regex line:
>
> > > > > r'^find/(?P[-\w]+)$
>
> > > > > and if I pull up the address:
>
> > > > >http://mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F
>
> > > > > I still get
>
> > > > > Not Found
>
> > > > > The requested URL /find/http://www.wired.com/wasnotfoundon this
> > > > > server.
>
> > > > > I did figure out how to decode the URL in python using unquote_plus(),
> > > > > but I cannot figure out this problem.
>
> > > > > On Oct 6, 1:27 pm, "Keith Eberle" <[EMAIL PROTECTED]> wrote:
>
> > > > > > it looks like you have mismatched parens, and no trailing slash,
> > > which will
> > > > > > matter if APPEND_SLASH = True.  the regex should look like:
>
> > > > > >     r'^find/(?P[-\w]+)/$'
>
> > > > > > should be urls.py too, not views.py.
>
> > > > > > keith
>
> > > > > > On Mon, Oct 6, 2008 at 1:17 PM, Merrick <[EMAIL PROTECTED]> wrote:
>
> > > > > > > I am trying to figure out how to match / capture a URL.
>
> > > > > > > views.py
> > > > > > > ===
> > > > > > > urlpatterns = patterns('',
> > > > > > >    url(r'^find/(?P(.*)$',
> > > > > > >        view = 'myapp.views.find',
> > > > > > >        name = 'find'
> > > > > > >    ),
>
> > > > > > > when I enter in this address:
>
> > > > > > > mydomain.com/find/www.wired.com
>
> > > > > > > my view / template are executed, but if I do this:
>
> > > > > > > mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F
>
> > > > > > > I get:
>
> > > > > > > Not Found
>
> > > > > > > The requested URL /find/http://www.wired.com/wasnotfoundonthis
> > > > > > > server.
>
>
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Regex pattern for URL matching

2008-10-06 Thread Merrick

keith, thanks for trying.

%2f is the encoded value of /, but urls contain other characters as
well not just alphanumeric.

I suspect this issue may have to do with apache or WSGI but not sure
what.

On Oct 6, 4:06 pm, "Keith Eberle" <[EMAIL PROTECTED]> wrote:
> quick solution, i think you could add the % to the regex  (i'm hardly a
> regex master):
>
> r'^find/(?P[%-\w]+)$
>
> keith
>
> On Mon, Oct 6, 2008 at 7:05 PM, Merrick <[EMAIL PROTECTED]> wrote:
>
> > I have narrowed down the problem to %2F in my url, anyone?
>
> > On Oct 6, 2:55 pm, Merrick <[EMAIL PROTECTED]> wrote:
> > > \w will only match alphanumeric characters, I need to match anything
> > > and will let my modelform verify that it is indeed a URL.
>
> > > On Oct 6, 2:43 pm, Merrick <[EMAIL PROTECTED]> wrote:
>
> > > > Thank you, I meant urls.py. APPEND_SLASH = False so I omitted the
> > > > trailing slash from the regex line:
>
> > > > r'^find/(?P[-\w]+)$
>
> > > > and if I pull up the address:
>
> > > >http://mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F
>
> > > > I still get
>
> > > > Not Found
>
> > > > The requested URL /find/http://www.wired.com/wasnotfound on this
> > > > server.
>
> > > > I did figure out how to decode the URL in python using unquote_plus(),
> > > > but I cannot figure out this problem.
>
> > > > On Oct 6, 1:27 pm, "Keith Eberle" <[EMAIL PROTECTED]> wrote:
>
> > > > > it looks like you have mismatched parens, and no trailing slash,
> > which will
> > > > > matter if APPEND_SLASH = True.  the regex should look like:
>
> > > > >     r'^find/(?P[-\w]+)/$'
>
> > > > > should be urls.py too, not views.py.
>
> > > > > keith
>
> > > > > On Mon, Oct 6, 2008 at 1:17 PM, Merrick <[EMAIL PROTECTED]> wrote:
>
> > > > > > I am trying to figure out how to match / capture a URL.
>
> > > > > > views.py
> > > > > > ===
> > > > > > urlpatterns = patterns('',
> > > > > >    url(r'^find/(?P(.*)$',
> > > > > >        view = 'myapp.views.find',
> > > > > >        name = 'find'
> > > > > >    ),
>
> > > > > > when I enter in this address:
>
> > > > > > mydomain.com/find/www.wired.com
>
> > > > > > my view / template are executed, but if I do this:
>
> > > > > > mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F
>
> > > > > > I get:
>
> > > > > > Not Found
>
> > > > > > The requested URL /find/http://www.wired.com/wasnotfoundon this
> > > > > > server.
>
>
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Regex pattern for URL matching

2008-10-06 Thread Merrick

I have narrowed down the problem to %2F in my url, anyone?



On Oct 6, 2:55 pm, Merrick <[EMAIL PROTECTED]> wrote:
> \w will only match alphanumeric characters, I need to match anything
> and will let my modelform verify that it is indeed a URL.
>
> On Oct 6, 2:43 pm, Merrick <[EMAIL PROTECTED]> wrote:
>
> > Thank you, I meant urls.py. APPEND_SLASH = False so I omitted the
> > trailing slash from the regex line:
>
> > r'^find/(?P[-\w]+)$
>
> > and if I pull up the address:
>
> >http://mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F
>
> > I still get
>
> > Not Found
>
> > The requested URL /find/http://www.wired.com/wasnot found on this
> > server.
>
> > I did figure out how to decode the URL in python using unquote_plus(),
> > but I cannot figure out this problem.
>
> > On Oct 6, 1:27 pm, "Keith Eberle" <[EMAIL PROTECTED]> wrote:
>
> > > it looks like you have mismatched parens, and no trailing slash, which 
> > > will
> > > matter if APPEND_SLASH = True.  the regex should look like:
>
> > >     r'^find/(?P[-\w]+)/$'
>
> > > should be urls.py too, not views.py.
>
> > > keith
>
> > > On Mon, Oct 6, 2008 at 1:17 PM, Merrick <[EMAIL PROTECTED]> wrote:
>
> > > > I am trying to figure out how to match / capture a URL.
>
> > > > views.py
> > > > ===
> > > > urlpatterns = patterns('',
> > > >    url(r'^find/(?P(.*)$',
> > > >        view = 'myapp.views.find',
> > > >        name = 'find'
> > > >    ),
>
> > > > when I enter in this address:
>
> > > > mydomain.com/find/www.wired.com
>
> > > > my view / template are executed, but if I do this:
>
> > > > mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F
>
> > > > I get:
>
> > > > Not Found
>
> > > > The requested URL /find/http://www.wired.com/wasnotfound on this
> > > > server.
>
>
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Regex pattern for URL matching

2008-10-06 Thread Merrick

Thank you, I meant urls.py. APPEND_SLASH = False so I omitted the
trailing slash from the regex line:

r'^find/(?P[-\w]+)$

and if I pull up the address:

http://mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F

I still get

Not Found

The requested URL /find/http://www.wired.com/ was not found on this
server.

I did figure out how to decode the URL in python using unquote_plus(),
but I cannot figure out this problem.


On Oct 6, 1:27 pm, "Keith Eberle" <[EMAIL PROTECTED]> wrote:
> it looks like you have mismatched parens, and no trailing slash, which will
> matter if APPEND_SLASH = True.  the regex should look like:
>
>     r'^find/(?P[-\w]+)/$'
>
> should be urls.py too, not views.py.
>
> keith
>
> On Mon, Oct 6, 2008 at 1:17 PM, Merrick <[EMAIL PROTECTED]> wrote:
>
> > I am trying to figure out how to match / capture a URL.
>
> > views.py
> > ===
> > urlpatterns = patterns('',
> >    url(r'^find/(?P(.*)$',
> >        view = 'myapp.views.find',
> >        name = 'find'
> >    ),
>
> > when I enter in this address:
>
> > mydomain.com/find/www.wired.com
>
> > my view / template are executed, but if I do this:
>
> > mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F
>
> > I get:
>
> > Not Found
>
> > The requested URL /find/http://www.wired.com/was not found on this
> > server.
>
>
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Regex pattern for URL matching

2008-10-06 Thread Merrick

\w will only match alphanumeric characters, I need to match anything
and will let my modelform verify that it is indeed a URL.


On Oct 6, 2:43 pm, Merrick <[EMAIL PROTECTED]> wrote:
> Thank you, I meant urls.py. APPEND_SLASH = False so I omitted the
> trailing slash from the regex line:
>
> r'^find/(?P[-\w]+)$
>
> and if I pull up the address:
>
> http://mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F
>
> I still get
>
> Not Found
>
> The requested URL /find/http://www.wired.com/was not found on this
> server.
>
> I did figure out how to decode the URL in python using unquote_plus(),
> but I cannot figure out this problem.
>
> On Oct 6, 1:27 pm, "Keith Eberle" <[EMAIL PROTECTED]> wrote:
>
> > it looks like you have mismatched parens, and no trailing slash, which will
> > matter if APPEND_SLASH = True.  the regex should look like:
>
> >     r'^find/(?P[-\w]+)/$'
>
> > should be urls.py too, not views.py.
>
> > keith
>
> > On Mon, Oct 6, 2008 at 1:17 PM, Merrick <[EMAIL PROTECTED]> wrote:
>
> > > I am trying to figure out how to match / capture a URL.
>
> > > views.py
> > > ===
> > > urlpatterns = patterns('',
> > >    url(r'^find/(?P(.*)$',
> > >        view = 'myapp.views.find',
> > >        name = 'find'
> > >    ),
>
> > > when I enter in this address:
>
> > > mydomain.com/find/www.wired.com
>
> > > my view / template are executed, but if I do this:
>
> > > mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F
>
> > > I get:
>
> > > Not Found
>
> > > The requested URL /find/http://www.wired.com/wasnot found on this
> > > server.
>
>
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Regex pattern for URL matching

2008-10-06 Thread Merrick

I am trying to figure out how to match / capture a URL.

views.py
===
urlpatterns = patterns('',
url(r'^find/(?P(.*)$',
view = 'myapp.views.find',
name = 'find'
),

when I enter in this address:

mydomain.com/find/www.wired.com

my view / template are executed, but if I do this:

mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F

I get:

Not Found

The requested URL /find/http://www.wired.com/ was not found on this
server.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: capture form input even after ValueError exists

2008-10-01 Thread Merrick

Yeah thanks, I guess I wasn't clear. I realize I don't have access to
cleaned_data but I want to validate my url the same way as django does
by default on a form - any pointers on how to accomplish that?

Also how do I access the form submission if not through
cleaned_data.get?



On Sep 30, 10:49 pm, Kenneth Gonsalves <[EMAIL PROTECTED]> wrote:
> On Wednesday 01 October 2008 01:35:55 am Merrick wrote:
>
> > All is not lost if a user enters an invalid code I still want to do
> > something with just the url, but I cannot get
> > form.cleaned_data.get('url'). Any ideas how to get the url inputted
> > and to clean it inside the ValueError branch of code above
>
> cleaned_data only gets produced if is_valid is true - so if you want
> cleaned_data, do validation on the code after that.
>
> --
> regards
> KGhttp://lawgon.livejournal.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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



capture form input even after ValueError exists

2008-09-30 Thread Merrick

My ModelForm has two input fields url and code, and I raise a
ValidationError if the code contains anything other than letters,
numbers and dashes. My logic looks something like this:

if form.is_valid():
...
return render_to_response('new.html', {'code': new.code})

if ValueError:
if form.cleaned_data.get('url'):

All is not lost if a user enters an invalid code I still want to do
something with just the url, but I cannot get
form.cleaned_data.get('url'). Any ideas how to get the url inputted
and to clean it inside the ValueError branch of code above

Ideas?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: question about return value when selecting next id from postgresql using nextval

2008-09-30 Thread Merrick

Thank you, I was doing this:

def encode_id(id):
...
number = id
charset = string.letters + string.digits
base = len(charset)
count = 0
while number:
digit = number % base
...

and kept getting an error, when I did this:

id = row[0]
encode_id(id)

I didn't realize that the L stood for long, anyhow this works:

id = int(row[0]
encode_id(id)





On Sep 30, 7:15 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Tue, 2008-09-30 at 15:08 -0700, Merrick wrote:
> > If I run the following query on psql:
>
> > SELECT nextval('redirect_link_id_seq');
>
> > it returns an integer, say 5
>
> > when I do the following with the django shell I get a different
> > result:
>
> > >>> def get_next_id():
> > ...     cursor = connection.cursor()
> > ...     cursor.execute("SELECT nextval('redirect_link_id_seq');")
> > ...     next_id = cursor.fetchone()
> > ...     return next_id
> > >>> row = get_next_id()
> > >>> row[0]
> > 5L
>
> > Of course I can cast to an integer
> > >>> int(row[0])
> > 5
>
> > But I was hoping someone could let me know why my return value is 5L
> > and not 5, sorry for such a noob question.
>
> Because that's what the db wrapper returns. In practice it makes
> effectively no difference. Historically, Python use to distinguish
> between longs and integers, but even in those days you could almost
> always just work with them as "numbers". Today, that's particularly
> true. Just use the value returned. Why do you need to it to have type
> "int" instead of type "long"?
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



question about return value when selecting next id from postgresql using nextval

2008-09-30 Thread Merrick

If I run the following query on psql:

SELECT nextval('redirect_link_id_seq');

it returns an integer, say 5

when I do the following with the django shell I get a different
result:

>>> def get_next_id():
... cursor = connection.cursor()
... cursor.execute("SELECT nextval('redirect_link_id_seq');")
... next_id = cursor.fetchone()
... return next_id
>>> row = get_next_id()
>>> row[0]
5L

Of course I can cast to an integer
>>> int(row[0])
5

But I was hoping someone could let me know why my return value is 5L
and not 5, sorry for such a noob question.
I
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



how to get CURRVAL()

2008-09-19 Thread Merrick

I have a function in my model where I need the next sequence id from
postgresql so i can create an encoded value based off it. Any ideas on
how to do this?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Store referer to form in database

2008-09-17 Thread Merrick

I have a form on the homepage of mydomain.com that instructs people to
submit their email address and we'll notify them when we launch our
service. For those visitors that submit the form, I want to store the
referer. I am able to print out the HTTP_REFERER on the same template
as the form but I cannot figure out how to store the correct referer
in the database.

I have the following in my views.py, the lines commented out are
approaches I took that were unsuccessful. I realize I could try a
hidden form variable but am wondering if there is something else I can
do.

# Create your views here.
from django.http import HttpResponseRedirect
from django.forms import ModelForm
from django.shortcuts import render_to_response
from permission.models import Sneezer

class SneezerForm(ModelForm):
class Meta:
model = Sneezer
exclude = ['ip_address', 'referer', 'timestamp']

def add_sneezer(request):
if request.method == 'POST':
#   referer = request.META.get("HTTP_REFERER", "")
#   line above generates an empty value in database
data = request.POST
#data = data.copy()
#data.update({"referer" : referer})
form = SneezerForm(data)
if form.is_valid():
new_sneezer = form.save(commit=False)
new_sneezer.ip_address = 
request.META.get("REMOTE_ADDR", "")
#new_sneezer.referer = request.META.get("HTTP_REFERER", 
"")
#stores mydomain.com as the value every time, thus its 
storing the
referer of the POST
new_sneezer.save()
return render_to_response('thanks.html')
else:
form = SneezerForm(initial={'referer':
request.META.get("HTTP_REFERER", "")})
return render_to_response('index.html', { 'form': form,
'original_referer': request.META.get("HTTP_REFERER", "") })

def index(request):
form = SneezerForm(initial={'referer':
request.META.get("HTTP_REFERER", "")})
return render_to_response('index.html', { 'form': form,
'original_referer': request.META.get("HTTP_REFERER", "") })


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: get_absolute_url() using related models slugs

2008-04-25 Thread Merrick

Thank you Malcolm and Karen, I had to step for the day but when I got
home I read your comments and fixed the issue which was exactly as you
both pointed out.

this helped make my photo model much more search friendly.

@permalink
def get_absolute_url(self):
return ('photo_detail',  None, { 'state' :
self.place.city.state.slug , 'city' : self.place.city.slug, 'place' :
self.place.slug, 'slug': self.slug })

and in my views.py

#photo
url(r'^photo/(?P[-\w]+)/(?P[-\w]+)/(?P[-\w]+)/
(?P[\-\d\w]+)/$',
  view = 'photologue.views.photo_detail',
  name = 'photo_detail',
),


On Apr 24, 11:43 am, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Thu, Apr 24, 2008 at 12:21 PM, Merrick <[EMAIL PROTECTED]> wrote:
>
> > Thank you, I updated get_absolute_url to take into consideration the
> > fact that I was erroneously using state_slug instead of state.slug and
> > the same with photo.slug and place.slug
>
> >def get_absolute_url(self):
> >return ('photo-detail',  None, { 'state' :
> > self.photo.place.city.state.slug , 'city' :
> > self.photo.place.city.slug, 'place' : self.photo.place.slug, 'slug':
> > self.slug })
>
> > >>> from photologue.models import *
> > >>> photo = Photo.objects.get(slug='golf-course-3')
> > >>> photo.get_absolute_url()
>
> > still getting this error:
>
> > AttributeError: 'RelatedManager' object has no attribute 'place'
>
> As Malcolm said, within get_absolute_url, self is already the Photo
> instance, so it is confusing what you are trying to get at when you use
> 'self.photo' here.  In fact given the models you have defined, self.photo is
> referencing the model manager for the set of Gallery instances that have
> self as 'featured_photo'.  (I think you might want to rethink that
> related_name specification, since it seems to be confusing enough to have
> tripped you up here.)
>
> Within get_absolute_url, to refer to the photo instance, just use self, not
> self.photo.  When you fix that you are going to hit an error because the
> Place model does not have a slug field, and yet you are trying to access it
> when you code self.place.slug.  I don't know what you are really intending
> to specify here.
>
> Karen
>
>
>
> > On Apr 24, 8:59 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
> > wrote:
> > > On Thu, 2008-04-24 at 08:55 -0700, Merrick wrote:
>
> > > [...]
>
> > > > ***Shell output
>
> > > > >>> from photologue.models import *
> > > > >>> photo = Photo.objects.get(slug='golf-course-3')
> > > > >>> photo.place.city.state_slug
> > > > Traceback (most recent call last):
> > > >   File "", line 1, in ?
> > > > AttributeError: 'City' object has no attribute 'state_slug'
>
> > > This is telling you exactly what the error is. You're accessing a
> > > non-existent attribute on the City model. Maybe you mean to state.slug
> > > instead of state_slug or maybe you mean something else there. In any
> > > case, there is no state_slug attribute.
>
> > > Malcolm
>
> > > --
> > > He who laughs last thinks slowest.http://www.pointy-stick.com/blog/
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: get_absolute_url() using related models slugs

2008-04-24 Thread Merrick

Thank you, I updated get_absolute_url to take into consideration the
fact that I was erroneously using state_slug instead of state.slug and
the same with photo.slug and place.slug

def get_absolute_url(self):
return ('photo-detail',  None, { 'state' :
self.photo.place.city.state.slug , 'city' :
self.photo.place.city.slug, 'place' : self.photo.place.slug, 'slug':
self.slug })

>>> from photologue.models import *
>>> photo = Photo.objects.get(slug='golf-course-3')
>>> photo.get_absolute_url()

still getting this error:

AttributeError: 'RelatedManager' object has no attribute 'place'


On Apr 24, 8:59 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Thu, 2008-04-24 at 08:55 -0700, Merrick wrote:
>
> [...]
>
> > ***Shell output
>
> > >>> from photologue.models import *
> > >>> photo = Photo.objects.get(slug='golf-course-3')
> > >>> photo.place.city.state_slug
> > Traceback (most recent call last):
> >   File "", line 1, in ?
> > AttributeError: 'City' object has no attribute 'state_slug'
>
> This is telling you exactly what the error is. You're accessing a
> non-existent attribute on the City model. Maybe you mean to state.slug
> instead of state_slug or maybe you mean something else there. In any
> case, there is no state_slug attribute.
>
> Malcolm
>
> --
> He who laughs last thinks slowest.http://www.pointy-stick.com/blog/
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: get_absolute_url() using related models slugs

2008-04-24 Thread Merrick

Sorry to confuse things, I actually thought putting the shell output
would give a bigger picture.

The problem I am trying to solve is getting related to
get_absolute_url()

>>> photo.get_absolute_url()
Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib/python2.4/site-packages/django/utils/functional.py",
line 55, in _curried
return _curried_func(*(args+moreargs), **dict(kwargs,
**morekwargs))
  File "/usr/lib/python2.4/site-packages/django/db/models/base.py",
line 478, in get_absolute_url
return settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' %
(opts.app_label, opts.module_name), func)(self, *args, **kwargs)
  File "/usr/lib/python2.4/site-packages/django/db/models/
__init__.py", line 31, in inner
bits = func(*args, **kwargs)
  File "/var/virtualhosts/picturemexico/photologue/models.py", line
351, in get_absolute_url
return ('photo-detail',  None, { 'state' :
self.photo.place.city.state_slug , 'city' :
self.photo.place.city_slug, 'place' : self.photo.place_slug, 'slug':
self.slug })
AttributeError: 'RelatedManager' object has no attribute 'place'


On Apr 24, 8:59 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Thu, 2008-04-24 at 08:55 -0700, Merrick wrote:
>
> [...]
>
> > ***Shell output
>
> > >>> from photologue.models import *
> > >>> photo = Photo.objects.get(slug='golf-course-3')
> > >>> photo.place.city.state_slug
> > Traceback (most recent call last):
> >   File "", line 1, in ?
> > AttributeError: 'City' object has no attribute 'state_slug'
>
> This is telling you exactly what the error is. You're accessing a
> non-existent attribute on the City model. Maybe you mean to state.slug
> instead of state_slug or maybe you mean something else there. In any
> case, there is no state_slug attribute.
>
> Malcolm
>
> --
> He who laughs last thinks slowest.http://www.pointy-stick.com/blog/
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



get_absolute_url() using related models slugs

2008-04-24 Thread Merrick

I am still learning Django, and appreciate all of the help I have
received. I spent a few hours on this and just cannot figure out how
to pull off the get_absolute_url() function the way I describe it
below for the Photo class. I want to use the slugs for related models
and step through multiple relations. I can get to the id's of the
related models as shown in the shell transcript below, but not the
slugs yet.

extracted from models.py

class State(models.Model):
state = models.CharField(max_length=100, unique=True)
slug = models.SlugField(prepopulate_from=('state',))

class City(models.Model):
state = models.ForeignKey(State)
featured_place = models.ForeignKey('Place', related_name='place',
null=True, blank=True)
city = models.CharField(max_length=100, unique=True)
slug = models.SlugField(prepopulate_from=('city',))

class Place(models.Model):
city = models.ForeignKey(City)
featured_gallery = models.ForeignKey('Gallery',
related_name='gallery', null=True, blank=True)


class Gallery(models.Model):
user = models.ForeignKey(User)
place = models.ForeignKey(Place)
featured_photo = models.ForeignKey('Photo', related_name='photo',
null=True, blank=True)
pub_date = models.DateTimeField(_('date published'),
default=datetime.now)
title = models.CharField(_('title'), max_length=100, unique=True)
slug = models.SlugField(_('slug'), prepopulate_from=('title',),
unique=True,
help_text=_('A "Slug" is a unique URL-
friendly title for an object.'))
is_public = models.BooleanField(_('is public'), default=True,
help_text=_('Public galleries will
be displayed in the default views.'))
photos = models.ManyToManyField('Photo', related_name='galleries',
verbose_name=_('photos'), filter_interface=models.HORIZONTAL)

class Photo(models.Model):
user = models.ForeignKey(User)
place = models.ForeignKey(Place)
image = models.ImageField(_('photograph'), upload_to=PHOTOLOGUE_DIR
+"/photos/%Y/%b/%d")
pub_date = models.DateTimeField(_('date published'),
default=datetime.now)
title = models.CharField(_('title'), max_length=100, unique=True)
slug = models.SlugField(_('slug'), prepopulate_from=('title',),
unique=True,
help_text=('A "Slug" is a unique URL-
friendly title for an object.'))

@permalink
def get_absolute_url(self):
return ('photo-detail',  None, { 'state' :
self.photo.place.city.state_slug , 'city' :
self.photo.place.city_slug, 'place' : self.photo.place_slug, 'slug':
self.slug })

***Shell output

>>> from photologue.models import *
>>> photo = Photo.objects.get(slug='golf-course-3')
>>> photo.place.city.state_slug
Traceback (most recent call last):
  File "", line 1, in ?
AttributeError: 'City' object has no attribute 'state_slug'

>>> photo.place.city.state_id
4

>>> photo.get_absolute_url()
return ('photo-detail',  None, { 'state' :
self.photo.place.city.state_slug , 'city' :
self.photo.place.city_slug, 'place' : self.photo.place_slug, 'slug':
self.slug })
AttributeError: 'RelatedManager' object has no attribute 'place'


Any hints would be appreciated.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: best practice for creating featured field

2008-04-20 Thread Merrick

Thank you, I had various as errors as you pointed out and as soon as I
implemented your suggestions and reset the database it all works now.

On Apr 20, 8:43 am, Peter Rowell <[EMAIL PROTECTED]> wrote:
> > featured_place = models.ForeignKey(Place, null=true, blank=true)
>
> 1. By any chance are you getting an error like "NameError: name 'true'
> is not defined"? The python keyword is "True", not "true".
>
> 2. If you reference a mode before it is defined, you need to supply a
> string for the referenced model.
>e.g., featured_place = models.ForeignKey('Place', null=True,
> blank=True)
>This only works for forward references to models in the same
> models.py file.
>
> 3. Regarding your error 'null value in column "featured_id" violates
> not-null constraint'.
> You may have added null=True in your ForeignKey declaration, you
> may even have tried to do a ./manage.py syncdb, but that won't affect
> your DB. Once a table exists, django will not ALTER it to match your
> new description. You have two choices:
>  a. Modify your DB directly using whatever tool you use -- command
> line, phpMyAdmin, or whatever.
>  b. Do a ./manage.py reset . WARNING: this will drop the
> tables (and their data) for *all* of the models in the named app, and
> then create them anew with the current definitions.
>
>   HTH,
>   Peter
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: best practice for creating featured field

2008-04-19 Thread Merrick

Oops my featured_place actually reads:

featured_place = models.ForeignKey(Place, null=true, blank=true)

On Apr 19, 9:57 pm, Merrick <[EMAIL PROTECTED]> wrote:
> I updated the City model:
>
> class City(models.Model):
> state = models.ForeignKey(State)
> featured_place = models.ForeignKey(Place, related_name=places)
> city = models.CharField(max_length=100, unique=True)
>
> but now I get another error when running syncdb:
>
> NameError: name 'Place' is not defined
>
> sorry for all the help requests here.
>
> On Apr 19, 9:41 pm, Merrick <[EMAIL PROTECTED]> wrote:
>
> > Thank you, I originally had featured_place as a foreign key and ran
> > into a problem:
>
> > null value in column "featured_id" violates not-null constraint
>
> > That is because before there is a place there has to be a city.
>
> > On Apr 19, 9:37 pm, Doug B <[EMAIL PROTECTED]> wrote:
>
> > > > What is the best practice for making it so when I toggle is_featured
> > > > to on for Balboa Park the admin enforces a rule that only one place
> > > > can be featured for a city. Hope that makes sense, thank you.
>
> > > You could override save on Place and unset the other places.  Although
> > > I think it might be better to change your models slightly:
>
> > > class City(models.Model):
> > >  city = models.CharField(max_length=100, unique=True)
> > >  featured_place=models.ForeignKey('Place')
>
> > > class Place(models.Model):
> > > city = models.ForeignKey(City)
> > > title = models.CharField(max_length=255)
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: best practice for creating featured field

2008-04-19 Thread Merrick

I updated the City model:

class City(models.Model):
state = models.ForeignKey(State)
featured_place = models.ForeignKey(Place, related_name=places)
city = models.CharField(max_length=100, unique=True)

but now I get another error when running syncdb:

NameError: name 'Place' is not defined

sorry for all the help requests here.

On Apr 19, 9:41 pm, Merrick <[EMAIL PROTECTED]> wrote:
> Thank you, I originally had featured_place as a foreign key and ran
> into a problem:
>
> null value in column "featured_id" violates not-null constraint
>
> That is because before there is a place there has to be a city.
>
> On Apr 19, 9:37 pm, Doug B <[EMAIL PROTECTED]> wrote:
>
> > > What is the best practice for making it so when I toggle is_featured
> > > to on for Balboa Park the admin enforces a rule that only one place
> > > can be featured for a city. Hope that makes sense, thank you.
>
> > You could override save on Place and unset the other places.  Although
> > I think it might be better to change your models slightly:
>
> > class City(models.Model):
> >  city = models.CharField(max_length=100, unique=True)
> >  featured_place=models.ForeignKey('Place')
>
> > class Place(models.Model):
> > city = models.ForeignKey(City)
> > title = models.CharField(max_length=255)
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: best practice for creating featured field

2008-04-19 Thread Merrick

Thank you, I originally had featured_place as a foreign key and ran
into a problem:

null value in column "featured_id" violates not-null constraint

That is because before there is a place there has to be a city.

On Apr 19, 9:37 pm, Doug B <[EMAIL PROTECTED]> wrote:
> > What is the best practice for making it so when I toggle is_featured
> > to on for Balboa Park the admin enforces a rule that only one place
> > can be featured for a city. Hope that makes sense, thank you.
>
> You could override save on Place and unset the other places.  Although
> I think it might be better to change your models slightly:
>
> class City(models.Model):
>  city = models.CharField(max_length=100, unique=True)
>  featured_place=models.ForeignKey('Place')
>
> class Place(models.Model):
> city = models.ForeignKey(City)
> title = models.CharField(max_length=255)
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



best practice for creating featured field

2008-04-19 Thread Merrick

I am using the admin to do all of my data input.

I have the following models:

class City(models.Model):
city = models.CharField(max_length=100, unique=True)

class Place(models.Model):
city = models.ForeignKey(City)
title = models.CharField(max_length=255)
is_featured = models.BooleanField(_('is featured'), default=False,
help_text=_('Featured place will
be displayed in the places_by_city view.'))

Lets say using the models above I want to have only one place be
featured per city. So if I have the following data:

Cities

San Diego
Los Angeles

Places
--
Balboa Park
Sea World
Petco Park

What is the best practice for making it so when I toggle is_featured
to on for Balboa Park the admin enforces a rule that only one place
can be featured for a city. Hope that makes sense, thank you.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ProgrammingError with PostgreSQL: operator does not exist: integer ~~* unknown

2008-04-19 Thread Merrick

I understand what you are saying the problem is. In my case here is
what sets this off:

class Meta:
unique_together = ('city', 'title',)

where city is a foreign key and now I see the mixed types.


On Apr 18, 8:58 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Fri, 2008-04-18 at 17:26 -0700, Merrick wrote:
> > I get the same problem as described here:
>
> > #6523
> >http://code.djangoproject.com/ticket/6523
>
> > There is a diff file which says it fixes the problem, how should I
> > proceed? If implement the diff, anyone care to tell me how please.
>
> We had a discussion about this behaviour on the dev list a while back
> and have decided that using inappropriate operators on the wrong field
> types (e.g. using LIKE on an integer) is just not going to work if the
> database doesn't auto-case. It's actually bad data design to rely on
> that and Django shouldn't have to carry the overhead for working around
> that (it would be extra overhead for every database backend, since every
> time the operator is used, we need to do a check for the backend type
> and then change the behaviour). Using casts everywhere at the database
> level also slows down query time quite a bit and, again, we aren't going
> to penalise people who are doing the right thing to accommodate those
> with bad design. Basically PostgreSQL 8.3 has started reporting an error
> for something that has always been more or less an error, but has been
> previously disguised.
>
> However, we still need to audit the internal uses to make sure we aren't
> inadvertently using these wrong types ourselves, which is why #6523
> (and, related, #6605) are still open.
>
> The short answer is to work out why you are trying to use these
> text-based operators on non-text fields and avoid doing that. It's
> wrong. However, it may not be your fault if it's something Django is
> doing, which is part of fixing that problem.
>
> Regards,
> Malcolm
>
> --
> If it walks out of your refrigerator, LET IT 
> GO!!http://www.pointy-stick.com/blog/
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



ProgrammingError with PostgreSQL: operator does not exist: integer ~~* unknown

2008-04-18 Thread Merrick

I get the same problem as described here:

#6523
http://code.djangoproject.com/ticket/6523

There is a diff file which says it fixes the problem, how should I
proceed? If implement the diff, anyone care to tell me how please.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Prepopulate Slugfied from Foreign Key without using the id

2008-04-17 Thread Merrick

Thank you for that, I will have to study that because it is a lot
cleaner than what I did.

I added the following to my City model below Class Meta:

def save(self):
  slug_parts = self.slug.split('-')
  num_slugs = len(slug_parts)
  state_position = (num_slugs - 1)
  state = State.objects.get(id=slug_parts[state_position])
  state_slug = state.state.lower()
  city_slug = ''

  for i in range (0, (state_position)):
  city_slug += slug_parts[i] + '-'

  self.slug = "%s%s" % ( city_slug, state_slug )
  super(City, self).save()


I know it's hack a job.

On Apr 17, 7:36 pm, "James Punteney" <[EMAIL PROTECTED]> wrote:
> The javascript is part of the Simple pages app I've been working on so you
> can view the code 
> here:http://code.google.com/p/django-simplepages/source/browse/trunk/simpl...
>
> It's a little different than what you are doing as I'm not pulling the
> display value of the select box, I'm actually getting another value from the
> foreign key object. I had to do the extra step of using django to print out
> a javascript hash with the id's of the SiteSections as the key and the url
> that I'm using to prepopulate text box (hence the reason this is a django
> template file and not a plain javascript file).
>
> Overall it's pretty close to what you are wanting to do though.
>
> Hope that helps,
> --James
>
> On Thu, Apr 17, 2008 at 4:53 PM, Merrick <[EMAIL PROTECTED]> wrote:
>
> > Hi James,
>
> > thank you for responding, can you point me in the right direction with
> > the javascript.
>
> > --Merrick
>
> > On Apr 17, 1:25 pm, "James Punteney" <[EMAIL PROTECTED]> wrote:
> > > I ran into this issue the other day wanting to use a foreign key value
> > to
> > > prepopulate a slugfield  and just getting the id (if anything).
> > According to
> > > the documentation[1] prepopulate doesn't support foreign keys, so I
> > ended up
> > > going the custom javascript route in order to get it working.
>
> > > --James
>
> > > [1]http://www.djangoproject.com/documentation/model-api/#slugfield
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Prepopulate Slugfied from Foreign Key without using the id

2008-04-17 Thread Merrick

Hi James,

thank you for responding, can you point me in the right direction with
the javascript.

--Merrick


On Apr 17, 1:25 pm, "James Punteney" <[EMAIL PROTECTED]> wrote:
> I ran into this issue the other day wanting to use a foreign key value to
> prepopulate a slugfield  and just getting the id (if anything). According to
> the documentation[1] prepopulate doesn't support foreign keys, so I ended up
> going the custom javascript route in order to get it working.
>
> --James
>
> [1]http://www.djangoproject.com/documentation/model-api/#slugfield
>
> On Thu, Apr 17, 2008 at 4:11 PM, Jeff Anderson <[EMAIL PROTECTED]>
> wrote:
>
> > Merrick wrote:
>
> > > I setup the classes below in my model and would like to have access to
> > > the name of the state in the City model for use in the SlugField. As
> > > it is, I get the state id not the name of the state in the slugfield
> > > when I add a City through the admin.
>
> > This is the correct behavior-- It needs to store the id in the database.
> > When you say "I get the id" where are you doing this from? A template?
>
> > Post the code that you are using to display the information, as your
> > models appear to be done correctly.
>
> > Jeff Anderson
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Prepopulate Slugfied from Foreign Key without using the id

2008-04-17 Thread Merrick

I setup the classes below in my model and would like to have access to
the name of the state in the City model for use in the SlugField. As
it is, I get the state id not the name of the state in the slugfield
when I add a City through the admin. I know the admin is aware of this
value because the select list shows me the state name, how can I
access that instead of the id of the foreign key.

I am on the latest version of django and am trying to avoid using
javascript. I am not using the built in US Statefield because this is
for an international project and another app I am using is not
compatible with new-forms admin thus local flavor is also not an
option. Thanks. -Merrick



class State(models.Model):
state = models.CharField(max_length=100, unique=True)

class Admin:
pass

def __str__(self):
return self.state

class Meta:
ordering = ['state']


class City(models.Model):
city = models.CharField(max_length=100, unique=True)
state = models.ForeignKey(State)
slug = models.SlugField(prepopulate_from=('city', 'state'), unique=True)
is_public = models.BooleanField(_('is public'), default=False,
help_text=_('Public cities will be
displayed in the default views.'))
class Admin:
list_filter = ['state']
def __unicode__(self):
  return '%s, %s' % (self.city, self.state)

class Meta:
verbose_name_plural = 'cities'
ordering = ['city']

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---