Search forms: keeping it clean

2008-05-23 Thread Will

Hello all.

When I say keeping it clean, I mean being as lazy as possible.

I have a bunch of  models, and for each I want a search form.

So, to keep it simple I'm using a ModelForm for each (see form code
below). Wonderful, instant form, thankyou Django.
Now, in my view, instead of accessing the POST data and creating a
queryset manually, I want to create a QuerySet based on all the fields
for which data has been entered (perhaps using a default search method
for each field) and using the AND operator everywhere. Is this
possible as standard, or will I need to subclass ModelForm and add a
method to generate such a queryset myself?

My rationale for this is if I've got a lovely ModelForm, which I
haven't needed to do anything but write a model for, then why should I
manually create the searches?

Thanks,

Will

==Form==
from django.newforms import ModelForm

class MySearchForm(ModelForm):
class Meta:
model = MyModel

==View==
def MyModelSearch(request):
if request.method == 'POST':
form = MyModelSearch(request.POST)
#GENERIC SEARCH LOGIC HERE
else:
form = MyModelSearch()
return render_to_response('search.html', {'form': form})
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Navigation components

2008-06-02 Thread Will

Hi all

I'd like to start a discussion about generating navigation components.
Despite their importance and their fairly generic nature, best
practice is not obvious to me after trawling through hundreds of
posts, blogs etc.

Anyone that's interested, could you briefly state how you do it,
perhaps answering the following questions?

A. Where do you get the information about the site structure?
E.g. Do you just have a static include file, perhaps store it in
the db, or work it out from URL confs?

B. How do you deal with indicating the current page in the nav
component?

This is what I'm thinking of doing -

A. Generate a two level nav component from my URLConf file, then cache
it heavily. I'm looking at using the name from named url patterns to
populate the anchor lables.

B. Use javascript (window.location.href or something) to change the
class of the current page element. This will be much quicker to
implement and not too obtrusive on failure.

Cheers,

Will T
--~--~-~--~~~---~--~~
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: Navigation components

2008-06-03 Thread Will

Thanks for your replies, chaps.

I need to mull this over, but I think I see what you're getting at
(using template inheritance). I've realised the breadcrumbs should be
easy (use Super to add to the breadcrumb section I suppose).
The bit I don't see is how you get the info about section navigation
into the context - is is hard-coded into the view? This is what I'd
like to avoid.

Cheers

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



psycopg2

2008-06-24 Thread Will

I'm working on a project I'd like to use Django for, though my first
hurdle will be convincing a team of highly qualified scientists,
programmers and computer scientists that this is a good idea.

Given we are most likely going to use PostgreSQL, This isn't
particularly inspiring:
http://www.initd.org/

Why should we trust psycopg2 to be a high quality piece of software?

Will
--~--~-~--~~~---~--~~
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: psycopg2

2008-06-24 Thread Will

>You're not asking it to do a whole hell of a lot.

In terms of security, perhaps this is the most critical part of the
stack? SQL injection is one of the nastiest security vulnerabilities
IMHO.

>Seriously, though, psycopg2 is an open source library with a history of
>working pretty well for what it does.

I'd like a bit of documentation though. Perhaps a bug tracker? I don't
have the resources, or the knowledge, to make full tests of psycopg2.

Neither did I find this particularly inspiring (2.0 release).
Federico wrote:
>To be honest some last minor patches and fixes went in mostly untested
>so I wanted to release another beta but given the fact that some pretty
>big projects are still using psycopg 1 only because "psycopg 2 is still
>in beta" I decided to go for the real one.
http://osdir.com/ml/python.db.psycopg.announce/2006-06/msg0.html

I love open source software, and I'm not asking for huge teams
supporting the code. It's just psycopg is the most disorganised
production open source project I've ever seen.
The trouble is getting organisations and businesses to believe in open
source. When the first page you get when googling psycopg is a rant
containing swear words, it's not particularly confidence inspiring.

Will
--~--~-~--~~~---~--~~
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: psycopg2

2008-06-24 Thread Will

Michael,

> > In terms of security, perhaps this is the most critical part of the
> > stack? SQL injection is one of the nastiest security vulnerabilities
> > IMHO.
>
> You don't have time to write 2-3 bad SQL queries and attempt
> injection?  We're talking 5 lines of python, and that includes import
> statements.

Is that substitute for a full suite of regression tests?  What about
buffer overflow attacks? There's probably loads of other attacks I
don't even know about.
It doesn't even sound as if psycopg gets tested before release.

> > I love open source software, and I'm not asking for huge teams
> > supporting the code. It's just psycopg is the most disorganised
> > production open source project I've ever seen.
>
> then you haven't seen a lot of open source?  idk what to tell you...

All I'm asking for is some reason to trust the integrity of psycopg,
and all I'm getting from you is sarcasm. Perhaps you could provide me
with some links?


Cheers,

Will
--~--~-~--~~~---~--~~
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: psycopg2

2008-06-24 Thread Will

I really didn't want to turn this into a fight, and I apologise if my
posts have seemed inflammatory.  I'd just like to be able to trust all
my stack.

Will



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

2008-06-24 Thread Will



On Jun 24, 7:06 pm, "James Bennett" <[EMAIL PROTECTED]> wrote:
> On Tue, Jun 24, 2008 at 12:20 PM, Will <[EMAIL PROTECTED]> wrote:
> > I really didn't want to turn this into a fight, and I apologise if my
> > posts have seemed inflammatory.  I'd just like to be able to trust all
> > my stack.
>
> Well, this is the thing: are you going to this level of detail on
> *every* part of your stack? Are you auditing the kernel and the C
> libraries? Are you checking the security of the firmware for the
> drives in your server?
>

No, because I have no reason to do so.
The psycopg project just doesn't inspire me with confidence.
I'm glad to know that it works fine, and it is widely used.

Will




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

2008-06-24 Thread Will

Thanks for taking the time to write that, Federico.

My worries stemmed from my not being able to find any clear
information on psycopg, but I feel a lot happier now.

Cheers

Will


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

2008-06-26 Thread Will


Perhaps there's another problem here.

As far as I know, Django doesn't support the pygresql or pg/python
drivers.
http://python.projects.postgresql.org/ A very trustworthy looking
website :)

http://www.djangoproject.com/documentation/design_philosophies/
>Loose coupling
>A fundamental goal of Django’s stack is loose coupling and tight cohesion. The 
>various layers of the framework shouldn’t “know” about each other unless 
>absolutely >necessary.

Couldn't Django be pluggable with respect to the Database drivers?
There's a DBAPI2 interface spec, therefore it should be possible.
Locking users into a particular technology is more of a Microsoft
philosophy :)

I'm not tied to an OS, Web Server, or a Database, so why a driver?
And please nobody get angry. I'm not angry. Even Federico wasn't angry
after I questioned the integrity of his project. Thanks Federico, btw
for your very useful info.

Will


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

2008-06-27 Thread Will


On Jun 26, 11:38 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:

> Erm... the database backends _are_ pluggable. Hence, the
> DATABASE_ENGINE setting.
>

I undersand that, but I'm stuck with psycopg or psycopg2 if I'm to use
postgres, aren't I?

Would I have to write an entire new backend for postgres, just to use
a different driver?

Cheers

Will
--~--~-~--~~~---~--~~
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: psycopg2

2008-06-27 Thread Will


> Erm... the database backends _are_ pluggable. Hence, the
> DATABASE_ENGINE setting.
>

Ah, sorry. Reading the Django book had led me to believe I was stuck
with psycopg:

http://www.djangobook.com/en/beta/chapter05/
>DATABASE_ENGINE tells Django which database engine to use. If you’re using a 
>database with Django, DATABASE_ENGINE must be set to one of the following 
>>strings:
>postgresql
>postgresql_psycopg2
>etc

I hadn't realised it was only 100 lines or so of code to write a new
backend.

Will
--~--~-~--~~~---~--~~
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: How to use SplitDateTimeWidget (getting TypeError)

2007-09-26 Thread Will

On Sep 25, 1:15 pm, Kyle Fox <[EMAIL PROTECTED]> wrote:
> I'm trying to use a SplitDateTimeWidget for a forms.DateTimeField
> field, but keep getting TypeError: "expected string or buffer"
>
> The traceback leads to `strptime.py`, which has `found =
> format_regex.match(data_string) `.  The local variables are:
>
> data_string = [u'2007-09-29', u'11:05:59.898833']
> format = u'%Y-%m-%d %H:%M:%S
>
> It looks like the SplitDateTimeWidget is returning an array of [date,
> time] strings, when it should be returning a single string.
>
> Does anyone know how to do this?  Am I using the SplitDateTimeWidget
> incorrectly?
>
> Thanks,
> Kyle.

I got this error too.  Make sure you use forms.SplitDateTimeField
instead of forms.DateTimeField.


--~--~-~--~~~---~--~~
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: Django docs failing with search docs - certificate has expired

2022-02-03 Thread Will
I'm having the same issue starting about 10 minutes ago. For 
docs.djangoproject.com and code.djangoproject.com. Root domain works fine.
On Wednesday, February 2, 2022 at 11:24:45 PM UTC-5 Mike Dewhirst wrote:

>
> Error 503 certificate has expired
>
> certificate has expired
>
>
> Guru Mediation:
>
> Details: cache-syd10147-SYD 1643862123 79021947
>
> 
>
> Varnish cache server
>
>
> -- 
> Signed email is an absolute defence against phishing. This email has
> been signed with my private key. If you import my public key you can
> automatically decrypt my signature and be sure it came from me. Just
> ask and I'll send it to you. Your email software can handle signing.
>
>

-- 
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/98de31ae-e897-4c8f-8591-381b287c7711n%40googlegroups.com.


urlize filter does not handle trailing 'dot-dot-dot' correctly

2014-11-04 Thread will
Hi, new guy around here.

I am an engineer for a startup (www.agolo.com, check us out :P). We work 
heavily with twitter content, and i've discovered that the urlize template 
tag/filter does not handle trailing 'dot-dot-dot' (which is common in tweet 
content due to all the truncation and whatnot) correctly, since it assume 
that the url can only have 1 trailing punctuation character. should I open 
a pull request for this, or was this problem raised before?

regards,
Will

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/85845fcb-606a-40b2-8df1-97afc6d4f1fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Best Django Open Source Project for Intermediate Django Learners

2015-09-01 Thread will
I have gone through official Django Poll app tutorial, Django Girls 
tutorial, and several simple examples. 

Could anyone recommend one or several best open source Django project for 
people like me to ramp up the django skills further?

Some good one I have heard about is as follows:

NewsBlur
Everyblock

However, these projects are huge. Any medium size, easily accessible 
projects available?

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d1ae4ad3-434a-461c-99b4-150aad26ccfd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Are Querysets threadsafe?

2008-10-29 Thread Will McGugan

Hi,

Are querysets threadsafe? i.e. If a query set object is shared across
requests, will it cause any issues? I ask because some of the code in
django/db/models/query.py looks like it might access the same
resources if called simultaneously from two threads.

Regards,

Will McGugan
http://www.willmcgugan.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
-~--~~~~--~~--~--~---



Query spanning two foreign keys

2008-11-15 Thread Will McCutchen

Hi all,

I've got the following models (simplified for this example):

from django.db import models
from django.contrib.auth.models import User

class Chat(models.Model):
name = models.CharField(max_length=256)

class Post(models.Model):
user = models.ForeignKey(User, related_name='posts')
parent = models.ForeignKey(Chat, related_name='posts')

Can anyone tell me the best way to get a unique list of the users who
have contributed to a specific chat?  I can do something like the
following, but I feel like there must be a more elegant way:

>>> chat = Chat.objects.get(pk=1)
>>> user = set([post.user for post in chat.posts.all()])

Any suggestions?  Do I need to resort to raw SQL?

Thanks,


Will.
--~--~-~--~~~---~--~~
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: Query spanning two foreign keys

2008-11-16 Thread Will McCutchen

On Nov 15, 7:55 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> This should do the job:
>
>         User.objects.filter(posts__parent__pk=1).distinct()

That does the trick.  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
-~--~~~~--~~--~--~---



Change message unicode issue

2008-12-05 Thread Will McGugan
Hi,

I'm getting an 500 error in my admin site when modifying an object
containing unicode. It seems to be an issue when constructing the change
message. Here's the details (running on Django 1.0). Any help would be
appreciated.


'ascii' codec can't decode byte 0xe2 in position 37: ordinal not in
range(128)


·/www/django-sites/itpp/itpp/django/contrib/admin/options.py in
change_view

594. change_message =
self.construct_change_message(request, form, formsets) ...

▶ Local vars

·/www/django-sites/itpp/itpp/django/contrib/admin/options.py in
construct_change_message

347. change_message.append(_('Changed
%(list)s for %(name)s "%(object)s".') ...



-- 
Will McGugan
http://www.willmcgugan.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
-~--~~~~--~~--~--~---



I'm moving to Oxford

2009-01-14 Thread Will McGugan
Hi,

I'm sending this out to everyone in my gmail contacts, because I'm lazy.
Apologies if you don't need to know this.

I'm moving to Oxford tomorrow (Thursday 15th). Please get in touch if you
need my new address. My landline will change, but you can always get me on
my mobile.

I wont have internet access at home from tomorrow, so apologies if emails go
unanswered till I get broadband again!

So long, London!

Will

-- 
Will McGugan
http://www.willmcgugan.com

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



how to display date nicely

2008-08-18 Thread Will Rocisky

I have a datetime object '2008-15-06 11:12:13'
I want to display it like 'June 6, 2008 at 11:12'



--~--~-~--~~~---~--~~
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: how to display date nicely

2008-08-18 Thread Will Rocisky

actually I have to do it in views, not template
I need some pure python code

On Aug 18, 5:14 pm, Jarek Zgoda <[EMAIL PROTECTED]> wrote:
> Wiadomość napisana w dniu 2008-08-18, o godz. 13:08, przez Will Rocisky:
>
> > I have a datetime object '2008-15-06 11:12:13'
> > I want to display it like 'June 6, 2008 at 11:12'
>
> You have to format it using strftime() or in template using built-in  
> "date" filter. Seehttp://www.djangoproject.com/documentation/templates/#date
> --
> We read Knuth so you don't have to. - Tim Peters
>
> Jarek Zgoda
> [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
-~--~~~~--~~--~--~---



how to pass value to other action

2008-08-19 Thread Will Rocisky

I am actually making a sort of wizard in which all values have to be
saved at the end.
I want to pass a variable from one action to another after pressing
'Next' with HttpResponseRedirect
--~--~-~--~~~---~--~~
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 populate data again after validation

2008-08-20 Thread Will Rocisky

I am not using builtin {{form}} to print form in template. I am using
my own  things.
Now, after validation, when it shows error and comes back to form, all
the data has disappeared.
How can I keep data in fields even after validation.

I am using render_to_response
--~--~-~--~~~---~--~~
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: how to populate data again after validation

2008-08-20 Thread Will Rocisky

I am just using...

model...
class Contact(models.Model):
Name = models.CharField(max_length=100)
email = models.CharField(max_length=100)
comments = models.TextField(blank=False)

form...
class ContactForm(ModelForm):
Name = forms.CharField(label='Name')
email = forms.EmailField(label='Email')
comments = forms.CharField(label='Comments',widget=forms.Textarea)

class Meta:
model = Contact

views...
f = ContactForm()
f = request.POST
if f.is_valid():
f.save()
return HttpResponseRedirect('/home/')
else:
ctx = {}
ctx['errors'] = f.errors
return render_to_response('contact.html',ctx)

when it doesn't save because validation failed, it renders
contact.html again, but blank. All previous data lost.

On Aug 20, 4:07 pm, "Emily Rodgers" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> How are you doing your validation? Is the form populating a model instance
> or doing something else?
>
> I would be helpful to see some of the function in your views file.
>
> Em
>
> > -Original Message-
> > From: django-users@googlegroups.com
> > [mailto:[EMAIL PROTECTED] On Behalf Of Will Rocisky
> > Sent: 20 August 2008 10:45
> > To: Django users
> > Subject: how to populate data again after validation
>
> > I am not using builtin {{form}} to print form in template. I
> > am using my own  things.
> > Now, after validation, when it shows error and comes back to
> > form, all the data has disappeared.
> > How can I keep data in fields even after validation.
>
> > I am using render_to_response
--~--~-~--~~~---~--~~
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: how to populate data again after validation

2008-08-20 Thread Will Rocisky

actually I feel comfortable with custom html stuff.. thats why.
ooopps yeah that was a typo since I typed everything while am on-the-
go :)

I am new to django so I don't really know what to do.
could you please a little more?
thanks

On Aug 20, 4:55 pm, "Emily Rodgers" <[EMAIL PROTECTED]> wrote:
> Why are you using your own  tags (just out of interest!)? It might be
> that you have just provided a cut down version of your code but from what I
> see, there are a few reasons why it may not be working properly.
>
> It looks like you are only passing the errors to the template, but not the
> other form values. If you want the previous data, you will need to put it in
> your context.
>
> Is any validation working at all, and is it saving any data to the db? It
> looks like you are calling is_valid on your POST data (not on an instance of
> your form object). If you want to pass your POST data to the form, you need
> to do something like this:
>
> f = ContactForm(request.POST)
>
> Or if you need to put more data in (or munged data):
>
> contact_instance = Contact(att=value)
> f = ContactForm(request.POST, instance=contact_instance)
>
> HTH
>
> Em
>
> > -Original Message-
> > From: django-users@googlegroups.com
> > [mailto:[EMAIL PROTECTED] On Behalf Of Will Rocisky
> > Sent: 20 August 2008 11:24
> > To: Django users
> > Subject: Re: how to populate data again after validation
>
> > I am just using...
>
> > model...
> > class Contact(models.Model):
> >    Name = models.CharField(max_length=100)
> >    email = models.CharField(max_length=100)
> >    comments = models.TextField(blank=False)
>
> > form...
> > class ContactForm(ModelForm):
> >    Name = forms.CharField(label='Name')
> >    email = forms.EmailField(label='Email')
> >    comments =
> > forms.CharField(label='Comments',widget=forms.Textarea)
>
> >    class Meta:
> >            model = Contact
>
> > views...
> > f = ContactForm()
> > f = request.POST
> > if f.is_valid():
> >     f.save()
> >     return HttpResponseRedirect('/home/')
> > else:
> >     ctx = {}
> >     ctx['errors'] = f.errors
> >     return render_to_response('contact.html',ctx)
>
> > when it doesn't save because validation failed, it renders
> > contact.html again, but blank. All previous data lost.
>
> > On Aug 20, 4:07 pm, "Emily Rodgers" <[EMAIL PROTECTED]> wrote:
> > > Hello,
>
> > > How are you doing your validation? Is the form populating a model
> > > instance or doing something else?
>
> > > I would be helpful to see some of the function in your views file.
>
> > > Em
>
> > > > -Original Message-
> > > > From: django-users@googlegroups.com
> > > > [mailto:[EMAIL PROTECTED] On Behalf Of Will Rocisky
> > > > Sent: 20 August 2008 10:45
> > > > To: Django users
> > > > Subject: how to populate data again after validation
>
> > > > I am not using builtin {{form}} to print form in template. I am
> > > > using my own  things.
> > > > Now, after validation, when it shows error and comes back
> > to form,
> > > > all the data has disappeared.
> > > > How can I keep data in fields even after validation.
>
> > > > I am using render_to_response
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



auto urls for methods

2008-08-21 Thread Will Rocisky

Is it possible (like Rails) to not to enter every method and it's url
everytime? And url should go to the method straight unless defined.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



AND OR in ifequal

2008-08-22 Thread Will Rocisky

how do you put AND, OR in ifequal statement of django?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



value taken through textarea is being displayed in one line

2008-08-26 Thread Will Rocisky

I am taking an input from user in text area, like comments.
but when I print them, they all display in one line.
how can I format them to display exactly how use entered them? (new
lines, tabs etc)
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



average posts per month?

2008-09-01 Thread Will Rocisky

How do I find average number of posts per month?
--~--~-~--~~~---~--~~
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: average posts per month?

2008-09-01 Thread Will Rocisky

yeah, I am visiting that group :)

On Sep 1, 6:55 pm, "Artis Caune" <[EMAIL PROTECTED]> wrote:
> On Mon, Sep 1, 2008 at 2:54 PM, Will Rocisky <[EMAIL PROTECTED]> wrote:
>
> > How do I find average number of posts per month?
>
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en
> :)
>
> --
> regards,
> Artis Caune
>
> <. CCNA
> <|
> <' didii FreeBSD
--~--~-~--~~~---~--~~
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: average posts per month?

2008-09-01 Thread Will Rocisky

Oh!

I am talking purely about Django models and queries here.
I have a model Post. I want to find out average number of posts posted
by user :D

On Sep 2, 1:04 am, "James Matthews" <[EMAIL PROTECTED]> wrote:
> On the sides it should say the stats!
>
>
>
>
>
> On Mon, Sep 1, 2008 at 6:09 AM, Will Rocisky <[EMAIL PROTECTED]> wrote:
>
> > yeah, I am visiting that group :)
>
> > On Sep 1, 6:55 pm, "Artis Caune" <[EMAIL PROTECTED]> wrote:
> > > On Mon, Sep 1, 2008 at 2:54 PM, Will Rocisky <[EMAIL PROTECTED]> wrote:
>
> > > > How do I find average number of posts per month?
>
> > > For more options, visit this group athttp://
> > groups.google.com/group/django-users?hl=en
> > > :)
>
> > > --
> > > regards,
> > > Artis Caune
>
> > > <. CCNA
> > > <|
> > > <' didii FreeBSD
>
> --http://www.goldwatches.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
-~--~~~~--~~--~--~---



Recursive relationship - two models, same table

2008-10-01 Thread Will Temperley

Hi All

I have a load of Institutions, some with departments, some not. So I
created a model that can represent this simple hierarchy. See models
at the bottom.

 Fine, but a bit confusing for users, plus if the user just wants to
deal with Institutions alone in the admin, they're faced with
institutions and departments.  I'm relying heavily on the admin app in
my project btw.

So, I've tried having two models - InstitutionDepartment and
Institution that have the same table but different managers- (see
below). Institution doesn't use the "parent" foreign key.  (Btw I
haven't used inheritance here cos copy and paste is quick and dirty.)

I also have an Address model and JobPosition model that depend on
"institution_department_id", therefore to make this work, I'll need
two Address models with the same table?

I've tried this and it works, it's just v messy! Is there a better way
to do this??
>From my point of view it would just be much easier to have multiple
ModelAdmin classes use a single Model, but I can't do this can I?


Cheers

Will T




class InstitutionDepartment(models.Model):
TYPE_CHOICES = (
('I', 'Institution'),
('D', 'Department'),
)
institution_department_id = models.AutoField(primary_key=True)
name = models.CharField(max_length=200)
acronym = models.CharField(max_length=10,  null=True, blank=True)
type = models.CharField(max_length=1,  choices=TYPE_CHOICES)
parent = models.ForeignKey('self',  null=True,  blank=True)
def __unicode__(self):
if self.parent:
return ' | '.join([self.parent.name,  self.name, ])
else:
return self.name
class Meta:
db_table = 'institution_department'
ordering = ['parent__name', 'name', ]

class Institution(models.Model):
TYPE_CHOICES = (
('I', 'Institution'),
('D', 'Department'),
)
institution_department_id = models.AutoField(primary_key=True)
name = models.CharField(max_length=200)
acronym = models.CharField(max_length=10,  null=True, blank=True)
objects = InstitutionManager()
type = models.CharField(max_length=1,  choices=TYPE_CHOICES)
def __unicode__(self):
return self.name
class Meta:
db_table = 'institution_department'


class StreetAddress1(StreetAddressAbstract):
institution_department =
models.OneToOneField(InstitutionDepartment)
class Meta(StreetAddressAbstract.Meta):
pass

class StreetAddress2(StreetAddressAbstract):
institution_department = models.OneToOneField(Institution)
class Meta(StreetAddressAbstract.Meta):
pass

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



Strange problem with 'syncdb' not finding application models

2008-10-20 Thread Will Boyce

I was throwing together a (supposedly quick!) project today to gather
some information from customers, however I hit a stumbling block a
while back and I now feel like I'm banging my head on a brick wall..

I've modified the syncdb process to be a bit more verbose:

..snip..
Loading granular_permissions
No models found for 
..snip..

But when I try the same from the shell:

>>> app_name = 'granular_permissions'
>>> mod = __import__(app_name, {}, {}, ['models'])
>>> mod

>>> getattr(mod, 'models')

>>> hasattr(mod, 'models')
True


This is making absolutely no sense to me. The file exists all the
time, why can't I import it all the time!?
--~--~-~--~~~---~--~~
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: Strange problem with 'syncdb' not finding application models

2008-10-20 Thread Will Boyce

Thanks for the quick response Daniel!

The only self-referencing import I can see is that __init__.py is
importing a model from the apps models.py:

[EMAIL PROTECTED]:~/ibd$ grep -n -r granular granular_permissions/
granular_permissions/__init__.py:8:from granular_permissions.models
import Permission


On Oct 20, 12:30 pm, Daniel Roseman <[EMAIL PROTECTED]>
wrote:
> On Oct 20, 12:26 pm, Will Boyce <[EMAIL PROTECTED]> wrote:
>
>
>
> > I was throwing together a (supposedly quick!) project today to gather
> > some information from customers, however I hit a stumbling block a
> > while back and I now feel like I'm banging my head on a brick wall..
>
> > I've modified the syncdb process to be a bit more verbose:
>
> > ..snip..
> > Loading granular_permissions
> > No models found for  > ibd/granular_permissions/__init__.pyc'>
> > ..snip..
>
> > But when I try the same from the shell:
>
> > >>> app_name = 'granular_permissions'
> > >>> mod = __import__(app_name, {}, {}, ['models'])
> > >>> mod
>
> >  > granular_permissions/__init__.pyc'>>>> getattr(mod, 'models')
>
> >  > granular_permissions/models.pyc'>>>> hasattr(mod, 'models')
>
> > True
>
> > This is making absolutely no sense to me. The file exists all the
> > time, why can't I import it all the time!?
>
> Sounds like a circular dependency problem to me. Is your app trying to
> import something that needs granular_permissions itself?
> --
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: trouble with Django and javascript

2009-02-01 Thread Will Matos
Onclick="submit();"
Will Matos
TCDI
Director of Technical Sales
4510 Weybridge Lane
Greensboro, NC  27407
336.232.5832 office
336.232.5850 fax
336.414.0467 mobile  

- Original Message -
From: django-users@googlegroups.com 
To: Django users 
Sent: Sun Feb 01 19:52:49 2009
Subject: Re: trouble with Django and javascript


Thanks for you reply.

However, if I change the 'submit' to button, how can I submit the form
to the server?

Regards
min

On Feb 2, 11:34 am, "Todd O'Bryan"  wrote:
> In addition to displaying the message, it's also submitting the form,
> so you see the text for a second and then the form reloads.
>
> Change the  instead of "submit" and see if that 
> helps.
>
> Todd
>
>
>
> On Sun, Feb 1, 2009 at 6:05 PM, min  wrote:
>
> > First I  have a form:
>
> > class TestForm(forms.Form):
> >  name = forms.CharField( max_length=30 )
> >  age = forms.CharField( max_length=30 )
>
> > Then in the views.py:
>
> > def Test_page(request):
>
> >  form = TestForm()
> >  variables = RequestContext(request, {
> >    'form': form,
> >  })
> >  return render_to_response('Test.html', variables)
>
> > In the temlates file, I want to add a iframe and a submit button. When
> > the submit button was clicked, some word will appear in the iframe.
> > The following code is the Test.html:
>
> > 
> > Test Result Page
> > 
> >      
> >              function test(){
> >                              var iframe = document.getElementById
> > ("test");
> >                              var d = iframe.contentDocument;
> >                              d.body.innerHTML = "This is a test";
> >                              }
> >      
> > 
> > 
> >   
> >        Name:{{form.name}}
> >        age: {{form.age}}
> >        
> >        
> >   
> > 
> > 
>
> > Now, the problem is that, when I clicked the submit button, the text
> > of "This is a test" will display in the iframe for one second, and
> > then disappear. Is there any one know what's wrong with my code?
>
> > thanks
> > min


--~--~-~--~~~---~--~~
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: trouble with Django and javascript

2009-02-01 Thread Will Matos
Onclick="test();submit();"
Will Matos
TCDI
Dir. of Tech. Sales

- Original Message -
From: django-users@googlegroups.com 
To: Django users 
Sent: Sun Feb 01 20:54:32 2009
Subject: Re: trouble with Django and javascript


If I use Onclick="submit();", how to add the javascript function " test
()" to that buttom?

thanks

On Feb 2, 11:58 am, "Will Matos"  wrote:
> Onclick="submit();"
> Will Matos
> TCDI
> Director of Technical Sales
> 4510 Weybridge Lane
> Greensboro, NC  27407
> 336.232.5832 office
> 336.232.5850 fax
> 336.414.0467 mobile  
>
>
>
> - Original Message -
> From: django-users@googlegroups.com 
> To: Django users 
> Sent: Sun Feb 01 19:52:49 2009
> Subject: Re: trouble with Django and javascript
>
> Thanks for you reply.
>
> However, if I change the 'submit' to button, how can I submit the form
> to the server?
>
> Regards
> min
>
> On Feb 2, 11:34 am, "Todd O'Bryan"  wrote:
> > In addition to displaying the message, it's also submitting the form,
> > so you see the text for a second and then the form reloads.
>
> > Change the  instead of "submit" and see if that 
> > helps.
>
> > Todd
>
> > On Sun, Feb 1, 2009 at 6:05 PM, min  wrote:
>
> > > First I  have a form:
>
> > > class TestForm(forms.Form):
> > >  name = forms.CharField( max_length=30 )
> > >  age = forms.CharField( max_length=30 )
>
> > > Then in the views.py:
>
> > > def Test_page(request):
>
> > >  form = TestForm()
> > >  variables = RequestContext(request, {
> > >    'form': form,
> > >  })
> > >  return render_to_response('Test.html', variables)
>
> > > In the temlates file, I want to add a iframe and a submit button. When
> > > the submit button was clicked, some word will appear in the iframe.
> > > The following code is the Test.html:
>
> > > 
> > > Test Result Page
> > > 
> > >      
> > >              function test(){
> > >                              var iframe = document.getElementById
> > > ("test");
> > >                              var d = iframe.contentDocument;
> > >                              d.body.innerHTML = "This is a test";
> > >                              }
> > >      
> > > 
> > > 
> > >   
> > >        Name:{{form.name}}
> > >        age: {{form.age}}
> > >        
> > >        
> > >   
> > > 
> > > 
>
> > > Now, the problem is that, when I clicked the submit button, the text
> > > of "This is a test" will display in the iframe for one second, and
> > > then disappear. Is there any one know what's wrong with my code?
>
> > > thanks
> > > min


--~--~-~--~~~---~--~~
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: trouble with Django and javascript

2009-02-01 Thread Will Matos
The problem is that the iframe is part of the main page. When the main page is 
refreshed, the iframe goes with it. Unless you have the form in a separate 
iframe the behavior will continue to be the same. 

W


- Original Message -
From: django-users@googlegroups.com 
To: Django users 
Sent: Sun Feb 01 21:07:28 2009
Subject: Re: trouble with Django and javascript


Not working. Still the same problem( when button is clicked, the text
of "This is a test" will display in the iframe for one second, and
then disappear.).

On Feb 2, 12:55 pm, "Will Matos"  wrote:
> Onclick="test();submit();"
> Will Matos
> TCDI
> Dir. of Tech. Sales
>
>
>
> - Original Message -
> From: django-users@googlegroups.com 
> To: Django users 
> Sent: Sun Feb 01 20:54:32 2009
> Subject: Re: trouble with Django and javascript
>
> If I use Onclick="submit();", how to add the javascript function " test
> ()" to that buttom?
>
> thanks
>
> On Feb 2, 11:58 am, "Will Matos"  wrote:
> > Onclick="submit();"
> > Will Matos
> > TCDI
> > Director of Technical Sales
> > 4510 Weybridge Lane
> > Greensboro, NC  27407
> > 336.232.5832 office
> > 336.232.5850 fax
> > 336.414.0467 mobile  
>
> > - Original Message -
> > From: django-users@googlegroups.com 
> > To: Django users 
> > Sent: Sun Feb 01 19:52:49 2009
> > Subject: Re: trouble with Django and javascript
>
> > Thanks for you reply.
>
> > However, if I change the 'submit' to button, how can I submit the form
> > to the server?
>
> > Regards
> > min
>
> > On Feb 2, 11:34 am, "Todd O'Bryan"  wrote:
> > > In addition to displaying the message, it's also submitting the form,
> > > so you see the text for a second and then the form reloads.
>
> > > Change the  instead of "submit" and see if that 
> > > helps.
>
> > > Todd
>
> > > On Sun, Feb 1, 2009 at 6:05 PM, min  wrote:
>
> > > > First I  have a form:
>
> > > > class TestForm(forms.Form):
> > > >  name = forms.CharField( max_length=30 )
> > > >  age = forms.CharField( max_length=30 )
>
> > > > Then in the views.py:
>
> > > > def Test_page(request):
>
> > > >  form = TestForm()
> > > >  variables = RequestContext(request, {
> > > >    'form': form,
> > > >  })
> > > >  return render_to_response('Test.html', variables)
>
> > > > In the temlates file, I want to add a iframe and a submit button. When
> > > > the submit button was clicked, some word will appear in the iframe.
> > > > The following code is the Test.html:
>
> > > > 
> > > > Test Result Page
> > > > 
> > > >      
> > > >              function test(){
> > > >                              var iframe = document.getElementById
> > > > ("test");
> > > >                              var d = iframe.contentDocument;
> > > >                              d.body.innerHTML = "This is a test";
> > > >                              }
> > > >      
> > > > 
> > > > 
> > > >   
> > > >        Name:{{form.name}}
> > > >        age: {{form.age}}
> > > >        
> > > >        
> > > >   
> > > > 
> > > > 
>
> > > > Now, the problem is that, when I clicked the submit button, the text
> > > > of "This is a test" will display in the iframe for one second, and
> > > > then disappear. Is there any one know what's wrong with my code?
>
> > > > thanks
> > > > min


--~--~-~--~~~---~--~~
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: Autogenerate a Model on Save

2009-02-02 Thread Will Matos
Agreed. Your class is being saved in a view method. Upon successful saves 
create a new one. 



From: django-users@googlegroups.com 
To: django-users@googlegroups.com 
Sent: Mon Feb 02 15:07:48 2009
Subject: Re: Autogenerate a Model on Save 


generally you should keep this type of business logic out of the model

the place to put it is either in the Form
or the view


class OrderModelForm(forms.ModelForm):

class Meta:
model = Order

def save_model(self, request, obj, form, change):
"""
Given a model instance save it to the database.
"""

if not change: # only when adding
obj.created_by = request.user
if(not obj.from_email):
obj.from_email = request.user.email
#create your invoice now

obj.save()


# and if you are using that in the admin then add it to the admin too:

class OrderAdmin(admin.ModelAdmin):

form = OrderModelForm


and register it







  felix :  
crucial-systems.com 



On Mon, Feb 2, 2009 at 8:50 PM, Alfonso  wrote:



I'm full of queries today!...This one seems a simple notion that I
can't get my head around...How would I get django to auto-generate a
new Invoice record and populate with some values when a user saves a
new Order record?  A custom def save(self) method?

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: Autogenerate a Model on Save

2009-02-02 Thread Will Matos
The downside to putting it in the form is that the form should only be used for 
presentation. Putting this logic in the form is pushing programatic decisions 
to the presentation layer. 

I believe the better approach is defining a view method that can be shared by 
multiple urls. 




From: django-users@googlegroups.com 
To: django-users@googlegroups.com 
Sent: Mon Feb 02 15:16:07 2009
Subject: Re: Autogenerate a Model on Save 



the view is the first, and most easily understandable place to put it. 

the form logic may make your head hurt more at first, but eventually you'll 
feel more comfortable putting it there.

nothing wrong with coding it in the view

but OTOH you will get the same functionality if you use the form in your own 
view or in the admin.
and if you create more views for different purposes, they can all use that form.




On Mon, Feb 2, 2009 at 9:09 PM, Will Matos  wrote:


Agreed. Your class is being saved in a view method. Upon successful 
saves create a new one. 





From: django-users@googlegroups.com 
To: django-users@googlegroups.com 
Sent: Mon Feb 02 15:07:48 2009
Subject: Re: Autogenerate a Model on Save 

generally you should keep this type of business logic out of the model

the place to put it is either in the Form
or the view


class OrderModelForm(forms.ModelForm):

class Meta:
model = Order

def save_model(self, request, obj, form, change):
"""
Given a model instance save it to the database.
"""

if not change: # only when adding
obj.created_by = request.user
if(not obj.from_email):
obj.from_email = request.user.email
#create your invoice now

obj.save()


# and if you are using that in the admin then add it to the admin too:

class OrderAdmin(admin.ModelAdmin):

form = OrderModelForm


and register it







 <http://crucial-systems.com/crucialwww/imgs/tartan46.gif> felix :  
crucial-systems.com 



On Mon, Feb 2, 2009 at 8:50 PM, Alfonso  
wrote:



I'm full of queries today!...This one seems a simple notion 
that I
can't get my head around...How would I get django to 
auto-generate a
new Invoice record and populate with some values when a user 
saves a
new Order record?  A custom def save(self) method?

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: How do I add a Custom ID Field that increments?

2009-02-02 Thread Will Hardy

There's no easy solution without saving the object to the database.
Auto incrementing fields (AutoField or just id) get their value from
the database, so they wont have one until you save. This is good
because it prevents multiple objects ever having the same value. One
way to do what you want is to save a new invoice to the database
straight away when the user clicks "add new invoice" and allow them to
edit it, but if you're using the admin site, this might not be
straightforward.

You wont need to create a new field by the way, you could simply make
a property that uses the ID field of a model:

@property
def invoice_id(self):
if self.id:
return 'INV%d' % self.id

But you wouldn't be able to search for the full INV001 string, you
would have to strip the INV beforehand or create a new charfield and
populate that on save (sounds like what you're doing)

If you don't want to have such obvious incrementing values for your
invoice numbers, you could use a perfect hash function to convert it
to a more obscure value, like
http://www.djangosnippets.org/snippets/1249/ (I wrote this snippet,
don't worry that two people voted against it, they didn't say why... I
have no idea... it's just a simple perfect hash function and base
converter, and it certainly does the job it was designed to do)

Cheers,

Will

--~--~-~--~~~---~--~~
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: Documentation for Download?

2009-02-11 Thread Will Hardy

Hi all,

Should the release tarball maybe contain pre-build html and pdf documentation?
That might be handy for those who don't want to install sphinx/latex etc.

Cheers,

Will

--~--~-~--~~~---~--~~
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: Linked Comboboxes

2009-02-13 Thread Will Matos
Nathalia, 
 
I believe you have a number of options here.
1.You can overide the template for that model by creating your own 
tempate and providing your custom javascript/ajax calls
that match the behaviour you're looking for.
To do this you have to replicate the admin template path in your 
local app.  
See :  
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#templates-which-may-be-overridden-per-app-or-model
 
2.You can add your custom ModelForm to the ModelAdmin instance of the 
model your wish to alter.  With this option you can
add your own complete Form with options including javascript/css.
 
3.  (Probably the easiest):
You can add a `media` option to your form where you provide the custom 
javascript for the form.  
See: 
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-media-definitions
 
  """
ModelAdmin media definitions¶ 
<http://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-media-definitions>
 

  There are times where you would like add a bit of CSS and/or JavaScript 
to the 

  add/change views. This can be accomplished by using a Media inner class 
on your ModelAdmin:

class ArticleAdmin(admin.ModelAdmin):
class Media:
css = {
"all": ("my_styles.css",)
}
js = ("my_code.js",)
Keep in mind that this will be prepended with MEDIA_URL. 
The same rules apply as regular media definitions on forms 
<http://docs.djangoproject.com/en/dev/topics/forms/media/#topics-forms-media> .
"""
See also: 
http://docs.djangoproject.com/en/dev/topics/forms/media/#topics-forms-media
 
WM
 


From: django-users@googlegroups.com [mailto:django-us...@googlegroups.com] On 
Behalf Of Nathalia Sautchuk Patrício
Sent: Friday, February 13, 2009 12:18 PM
To: django-users@googlegroups.com
Subject: Linked Comboboxes


Hi people,

I'm new here and newbie in Django.

I have a problem and I've tried to find the solution searching at Google but I 
didn't find it.

I'm using the Django-admin and on one of my pages there are two combo-boxes 
related. I would like to filter the options in the second combo-box based on 
what is selected in the first field.

Is It possible at Django-admin, isn´t? How?

Thanks


Nathalia Sautchuk Patrício
http://stoa.usp.br/nathaliapatricio/weblog/

Antes de imprimir, pense em sua responsabilidade social e com o MEIO AMBIENTE.




--~--~-~--~~~---~--~~
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: Does fixtures loading invoke custom save method?

2009-04-13 Thread Will Hardy

Yes it is correct: fixtures only load data into the database.

If you want the .save() method to be called, you could use the the
dumpscript management command I wrote in django_extensions:

http://github.com/django-extensions/django-extensions/tree/master

Cheers,

Will

--~--~-~--~~~---~--~~
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: Blocking multiple form submissions from the same IP address

2009-04-26 Thread Will Hardy

I would allow the multiple submissions, but make a note of any IP
addresses to let you exclude the data in the analysis stage.  From
memory the following "meta" variables might be relevant:
HTTP_CLIENT_IP, REMOTE_ADDR, HTTP_X_FORWARDED_FOR comma separated)

Although I don't know who your users are, people behind a firewall
will have the same IP, so will people who switch browsers or close
cookie-cleaning browsers to complete the survey at another time. Plus
by doing it this way, you may be able to stop the more determined
participants, who would try methods you wouldn't be able to detect if
they knew that their data weren't being accepted.

If this is a more scientific survey, doing it this way helps you show
that the data are valid (you can say in your report that X
participants had the same IP address and have therefore been
excluded).

Cheers,

Will

--~--~-~--~~~---~--~~
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: Overwrite send_mail

2009-05-10 Thread Will Hardy

The test runner does something similar if I remember correctly, have a
look in django.test.utils and see if you can make something useful out
of that.

Cheers,

Will

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



Re: django decimal field query issue

2009-05-10 Thread Will Hardy

Firstly, I would very seriously recommend using geodjango for anything
that deals with longitude and latitude. I would also recommend using
IntegerField if your decimal_places is going to be 0.

As for you question, I have no idea why it wouldn't work. There seems
to be a space in your failing Decimal() test, but that wouldn't raise
an ObjectDoesNot exist error.

But using PointField in geodjango would probably avoid these issues anyway.

Cheers,

Will

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



Need a binary database field for a Django application.

2009-05-11 Thread Will Kraytos
Hi there,

My company's application needs to store binary data in the database. I need
it to work at least across the two database systems we're currently using:
Postgres (bytea) for production, SQLite3 (BLOB) for development.

What are my options?

The only relevant ticket[1] causes me to believe there's no builtin support
for this in Django. I'd much rather have that field supported on a Django
Model, but if that's currently impossible, I'm willing to use it directly
through a SQL query and/or on a separate table, or any other solution - as
long as it's robust and works well for both Postgres and SQLite3.

Thanks,

W.K.

---

[1] http://code.djangoproject.com/ticket/2417

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



Re: Need a binary database field for a Django application.

2009-05-11 Thread Will Kraytos

On May 11, 7:55 am, Karen Tracey  wrote:
> Have you investigated creating your own custom field:
>
> http://docs.djangoproject.com/en/dev/howto/custom-model-fields/

Thanks, I did look at that briefly. Was hoping there was some sort of
built-in support that wouldn't require me to define my own custom
field from scratch, because:

1) Writing, testing and maintaining such a field (that needs, for
example, to work consistently across databases) seems like a lot of
work to do as just one framework user.

2) For such a common, reasonable need, I was really hoping I wouldn't
have to mess with Django at such a core level, especially as I'm
relatively new to the framework and by no means an expert.

Unfortunately, that might be the only way until ticket #2417 gets
resolved (after more than 3 years...)?

Thanks,

W.K.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



get_or_create not atomic?

2009-05-12 Thread Will McGugan
Hi,

I recently tracked down a strange bug in our site where 2 object existed but
the code was expecting only one.

I think this is due to get_or_create, which doesn't appear to be atomic.
What I assume happened is that two requests came in close together and
tested for the existence of the object I was creating. Both requests
detected that the object didn't exist and went on to create a new one.

Could this be the case? And if so, should I not expect 'get_or_create' to be
an atomic operation?


Regards,

Will McGugan

-- 
Will McGugan
http://www.willmcgugan.com

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



RE: Need help for nested list in template

2009-05-19 Thread Will Matos


{%for item in final_list%}
 {%for val in item%}
{{val.id}}, {{val.val}}, {{val.msg}}
{%endfor%}
{%endfor%}



-Original Message-
From: django-users@googlegroups.com
[mailto:django-us...@googlegroups.com] On Behalf Of laspal
Sent: Tuesday, May 19, 2009 9:47 AM
To: Django users
Subject: Need help for nested list in template


Hi,
My model is :
   id  val msg
   20 1234 text
   20 1245text
   20 1275  text
   20 1356  text

so I have to display record in calendar format.
I am doing it in this way:
final_list =[]
somelist = [1200, 1250, 1300, 1350, 1400]
val = 0
i = iter(range(5))
testing_list =[]
for item in i:
user_status_list = UserStatus.objects.filter(id =20,time__gte
= somelist[val], time__lte = somelist[val+1))
  for item in user_status_list:
   testing_list.append(item)

final_list.append(testing_list)

so my final list should look like:

[ [  [20, 1234, sdfs], [20, 1245, sdffd]  ],  [ 20,1275, dfdfgf], [ ],
[20, 1356, dsfdf] ]

wanted to know How can I use this list in my template.
for item in final_list:
 for val in item:
print val.id, val.val, val.msg

which is wrong.
how can I fix this.

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: Parsing the arguments in HTTP GET

2009-05-19 Thread Will Matos

You wouldn't match this using a url pattern.  The rest of the query
string will be in the request.GET list.  So you can do the following:

ui=request.GET['ui']
shva=request.GET['shva']
name=request.GET['name']

you'll probably want to check that it exists first by doing:
  if 'ui' in request.GET:
ui=request.GET['ui']

or you can default it by doing:
  ui=request.GET.get('ui','defaultvalue')


W

-Original Message-
From: django-users@googlegroups.com
[mailto:django-us...@googlegroups.com] On Behalf Of MohanParthasarathy
Sent: Friday, May 15, 2009 5:56 PM
To: Django users
Subject: Parsing the arguments in HTTP GET


Hi,

I am very new to django. I am following along the tutorial. But I want
to be able to parse the URL which has the following form:

http://example.com/data/?ui=2&shva=1#label&name=/fetch

>From what I can tell, i can't match the whole thing using the url
pattern. I can parse up till "http://example.com/data"; and the rest in
the code. Where can i find examples/tutorials for the above format ?


thanks
mohan





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



RE: Need help for nested list in template

2009-05-19 Thread Will Matos

In this case a dictionary would not be necessary if he is indeed adding
the model object itself:

>  user_status_list = UserStatus.objects.filter(id =20,time__gte
> = somelist[val], time__lte = somelist[val+1))
>   for item in user_status_list:
>testing_list.append(item)
>

It appears he is appending the UserStatus instance. 

W
-Original Message-
From: django-users@googlegroups.com
[mailto:django-us...@googlegroups.com] On Behalf Of Tom Evans
Sent: Tuesday, May 19, 2009 10:33 AM
To: django-users@googlegroups.com
Subject: Re: Need help for nested list in template


On Tue, 2009-05-19 at 06:46 -0700, laspal wrote:
> Hi,
> My model is :
>id  val msg
>20 1234 text
>20 1245text
>20 1275  text
>20 1356  text
> 
> so I have to display record in calendar format.
> I am doing it in this way:
> final_list =[]
> somelist = [1200, 1250, 1300, 1350, 1400]
> val = 0
> i = iter(range(5))
> testing_list =[]
> for item in i:
> user_status_list = UserStatus.objects.filter(id =20,time__gte
> = somelist[val], time__lte = somelist[val+1))
>   for item in user_status_list:
>testing_list.append(item)
> 
> final_list.append(testing_list)
> 
> so my final list should look like:
> 
> [ [  [20, 1234, sdfs], [20, 1245, sdffd]  ],  [ 20,1275, dfdfgf], [ ],
> [20, 1356, dsfdf] ]
> 
> wanted to know How can I use this list in my template.
> for item in final_list:
>  for val in item:
> print val.id, val.val, val.msg
> 
> which is wrong.
> how can I fix this.
> 
> thanks...
> 

Build a dict instead, where you wish to refer to specific elements.

Eg:

foo = [ { 'id': 20, 'name': sdfs, }, { . } ]

and 

{% for item in foo %}
{{ item.name }}
{% endfor %}

Cheers

Tom




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



RE: Dynamic ForeignKey using or how ?

2009-05-19 Thread Will Matos

You can use model inheritance

class SomeCommonNameHere(models.Model):
title = models.CharField(max_length=100)
body = models.TextField()

class Casts(SomeCommonNameHere):
somecastfield = models

class Articles(SomeCommonNameHere):
somearticlefield = models...

class Faves(models.Model):
post = models.ForeignKey(SomeCommonNameHere)
user = models.ForeignKey(User,unique=True)

you can then access the subclass' specific fields by referencing:
#where fave is an instance of Faves...  
fave.post.articles.somearticlefield...
 or
fave.post.casts.somecastfield...



You may also want to look at proxy classes.

Checkout
http://docs.djangoproject.com/en/dev/topics/db/models/#multiple-inherita
nce


Will
-Original Message-
From: django-users@googlegroups.com
[mailto:django-us...@googlegroups.com] On Behalf Of Anakin
Sent: Tuesday, May 19, 2009 5:29 AM
To: Django users
Subject: Dynamic ForeignKey using or how ?


i want to use 2 model in one foreignkey, i think its dynamic
foreignkey

it means;

i have 2 model named screencasts and articles. and i have a fave
model, for favouriting this model entrys. can i use model dynamicly ?

class Articles(models.Model):
title = models.CharField(max_length=100)
body = models.TextField()

class Casts(models.Model):
title = models.CharField(max_length=100)
body = models.TextField()

class Faves(models.Model):
post = models.ForeignKey(CASTS-OR-ARTICLES)
user = models.ForeignKey(User,unique=True)

is it possible ?

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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



RE: How do I override __unicode__ for User?

2009-05-20 Thread Will Matos

If you're using the most recent version of django you can use a Proxy
Model:
(I think this will work but I've never tried it)
class Author(User):
class Meta:
proxy = True

#Here you redefine the default behavior of
#of the __unicode__ function
def __unicode__(self):
author = ("%s %s" % (self.first_name,self.last_name)).strip()
if len(author)> 0: return author
return self.username

...
class BlogPost(models.Model):
title = models.CharField(max_length=150)
body = models.TextField()
author = models.ForeignKey(Author)
timestamp = models.DateTimeField()


If not just write a custom getAuthor() method:

class BlogPost(models.Model):
title = models.CharField(max_length=150)
body = models.TextField()
author = models.ForeignKey(User)
timestamp = models.DateTimeField()

def getAuthor(self):
theauthor = ("%s %s" %
(self.author.first_name,self.author.last_name)).strip()
if len(theauthor)> 0: return theauthor
return str(self.author)


W

-Original Message-
From: django-users@googlegroups.com
[mailto:django-us...@googlegroups.com] On Behalf Of Thierry
Sent: Sunday, May 17, 2009 4:59 PM
To: Django users
Subject: How do I override __unicode__ for User?


I currently have a blog model:

class BlogPost(models.Model):
title = models.CharField(max_length=150)
body = models.TextField()
author = models.ForeignKey(User)
timestamp = models.DateTimeField()

Right now, author is returning the default User.username.  I have
other models who has a ForeignKey to User, I want them to keep
defaulting to username while for Blogpost, I want it to return
"first_name last_name".  How can I customize the above so that author
returns me "first_name last_name" if they are present?


--~--~-~--~~~---~--~~
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: Ignoring the word "The"

2009-06-03 Thread Will Hardy

A more general solution is to create a another database field for
sorting/searching.

If you override the model's save() method to copy the field's value,
removing any characters you don't want (it could be language
independent, so would remove "Der/Die/Das" from german titles, or it
can do anything else your heart fancies).

Then all you need to do is do your searching/sorting on the new field.

Cheers,

Will

--~--~-~--~~~---~--~~
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: FW: Select models based on m2m relationship.

2009-09-17 Thread Will Matos
Leon,


Use ajax and json.

Create a view method that returns a json list of actors and their ids, then
populate your list with this.



>
> > -Original Message-
> > From: django-users@googlegroups.com
> > [mailto:django-us...@googlegroups.com] On Behalf Of Léon Dignòn
> > Sent: Wednesday, September 16, 2009 8:05 AM
> > To: Django users
> > Subject: Re: Select models based on m2m relationship.
> >
> >
> > bump
> >
> > On 15 Sep., 19:36, Léon Dignòn  wrote:
> > > Hello,
> > >
> > > I have a m2m relationship like this:
> > >
> > > class Actor(models.Model):
> > > name = models.CharField(unique=True) class Movie(models.Model):
> > > name = models.CharField(unique=True)
> > > actors = models.ManyToManyField(Actor) class
> > > Comment(models.Model):
> > > actor = models.ForeignKey(Actor)
> > > movie = models.ForeignKey(Movie)
> > > comment = models.CharField()
> > >
> > > Every actor belongs to a number movies, every movie
> > contains a number
> > > of actors.
> > >
> > > What I want to achieve is, that in the form I chose a movie
> > from the
> > > movie-dropdown list, then the actor-dropdown displays only actors
> > > acting in that particular movie. This can happen with javascript,
> > > ajax, or any other good stuff.
> > >
> > > I don't know wheter to use javascript, or ajax, or
> > whatever. I don't
> > > know if my model is good. Please help me starting with this. It's a
> > > little complex at the moment :)
> > > >
> >
>

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



ecommerce design decision needed :-)

2009-11-03 Thread Will Hardy

Dearest Django community,

I'm working on a ecommerce framework to help keep my sites
efficient/modular/maintainable. I'm pretty happy with my backend, but
I can't work out how I want it to be made accessible to
views/templates.

Currently it uses a declarative syntax to define the items, extras and
totals that a cart has, eg:

from rollyourown import shopping
from myapp.tax import calculate_tax

class CartPurchase(shopping.ModelPurchase):
# ITEMS
items = shopping.Items(attribute="items",
item_amount_from="model.item_price")
vouchers  = shopping.Items(attribute="vouchers",
item_amount_from="self.get_voucher_amount")

# EXTRAS
tax   = shopping.Extra("GST", amount=calculate_tax, included=True)
discount  = shopping.Extra()
delivery  = shopping.Extra()

# TOTALS
items_total   = shopping.Total('items')
items_pretax  = shopping.Total('items', '-tax')
vouchers_total= shopping.Total('vouchers')
total = shopping.Total(prevent_negative=True)

def get_delivery_amount(self, instance):
return "10.01"

def get_voucher_amount(self, instance):
return (-Decimal(instance.percent * self.items_total) /
100).quantize(Decimal("0.01"))

from myapp import models
shopping.register(models.Cart, CartPurchase)

(See http://code.google.com/p/rollyourown/wiki/RollyourownShopping for
more info on this)

That bit's fine! But the views and templates somehow need to know
about these totals and amounts. They generally have access to an
instance of your Cart (or Order etc) model, but that wont have these
totals in it. I really need some help deciding on how to:
 1) let the developer access these totals. Currently, the come with an
object that has to be retrieved eg "shopping.get(MyModel, request)".
 2) what should such an object look like. Current I'm automatically
generating a proxy model, with a ._shopping attribute which provides
all the totals. But I don't like the look of this. Maybe the system
should just return the object with the totals and a link to the
original model. Maybe the view should provide both as separate
variables.

So my question to everyone is:
* What sort of an object would you have in your views/templates? A
modified model (with all your special methods) with the cart totals
attached somehow? A cart totals object with the model attached or some
sort of evil hybid monster?
* How should this object be retrieved? Through a central repository,
or maybe automatically attached to the model (I'm not sure that's even
possible).

I hope this all makes sense, it's a bit tricky to describe a project
and its design problem in a short email. Thanks to anyone who takes
the time to understand what's going on here. I hope that the framework
I end up with will be useful (it's pretty damn useful to me so far :-)

Cheers,

Will

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



MySQLdb on Ubuntu 10.10

2010-10-12 Thread Will McGugan
Hi,

I've just upgraded my development machine from Ubuntu 10.04 to 10.10.
Unfortunately, now my Django apps wont start, I get the following
traceback on runserver:


File "/usr/local/lib/python2.6/dist-packages/django/core/management/
commands/runserver.py", line 48, in inner_run
self.validate(display_num_errors=True)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/
base.py", line 245, in validate
num_errors = get_validation_errors(s, app)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/
validation.py", line 22, in get_validation_errors
from django.db import models, connection
  File "/usr/local/lib/python2.6/dist-packages/django/db/__init__.py",
line 75, in 
connection = connections[DEFAULT_DB_ALIAS]
  File "/usr/local/lib/python2.6/dist-packages/django/db/utils.py",
line 91, in __getitem__
backend = load_backend(db['ENGINE'])
  File "/usr/local/lib/python2.6/dist-packages/django/db/utils.py",
line 32, in load_backend
return import_module('.base', backend_name)
  File "/usr/local/lib/python2.6/dist-packages/django/utils/
importlib.py", line 35, in import_module
__import__(name)
  File "/usr/local/lib/python2.6/dist-packages/django/db/backends/
mysql/base.py", line 14, in 
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
module: libmysqlclient_r.so.15: cannot open shared object file: No
such file or directory

I realise this probably isn't specifically a Django issue, but it
sounds like an issue that other Django devs would have experienced.

Any help would be appreciated...

Will

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



a request for some brain picking

2010-01-01 Thread Will Dampier
An open call,


This is Will Dampier, I've been an avid python and django programmer for the
past two years or so.  I've worked on a few in-house django projects and
I've been looking for a project to "give-back" to the community.  I've
always worked on the "programming" side of projects and have only dabbled on
the "design" side.  Whenever I've started a new project I've scoured the
internet for django templates that come complete with css, images, etc. and
always come up empty.

So I was thinking of making a "meta"-django project.  I could make a site
that allows designers to upload django-templates against a well defined set
of models, views, forms, etc.  Then users could switch between templates and
see how more "complex" examples function.  This would be useful for
designers to advertise their skills and for newbies to get a richer set of
functions.  Something akin to the CSS Zen Garden.

I'm looking for a collaborator or two ... or even just a few people to pick
their brains about some of the details.  I have some code in a git-hub
repository http://github.com/JudoWill/DjangoTemplateRepository/ and I've got
about a dozen google-wave invitations if people would like to try
collaborating that way.  If you wouldn't mind either forwarding this to
anyone you think would be interested or posting it on your blog.

Thanks in advance,
Will

--

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: a request for some brain picking

2010-01-01 Thread Will Dampier
I agree I'll be limiting things.  And I don't expect that you'd be
able to download the templates from this website and plug it into your
own without any modification what so ever.  The standardization comes
from the limiting of what I actually put in the context-dictionary
when I render the template.

I hope this will become a resource for people to download templates
that they can "tinker" into their own django programs.  I've noticed
that everytime I start a django project I get the views, forms,
models, etc. programmed easily but I stare at a blank editor screen
trying to write the template.  If I had a place to go and find a
"slick-looking" template to tinker with I'd be able to do things even
faster.

I'm hoping to make this into an ideal place for people to demonstrate
the tricks they use in constructing their templates ... stuff like how
they arrange the "blocks", which css items they use, whether they use
lists or tables, how they implement 'nav-bars', etc.



On Jan 1, 5:12 pm, aditya  wrote:
> Will,
> Django is much more flexible over template-based systems like
> Wordpress or Tumblr. Wordpress standardizes a lot of things so generic
> templates are easy to make and will work on just about any Wordpress
> installation. It seems to me like to have templates in Django you'd
> have to standardize things somehow...but that would result in loss of
> flexibility.
>
> Aditya
>
> On Jan 1, 1:06 pm, Will Dampier  wrote:
>
> > An open call,
>
> > This is Will Dampier, I've been an avid python and django programmer for the
> > past two years or so.  I've worked on a few in-house django projects and
> > I've been looking for a project to "give-back" to the community.  I've
> > always worked on the "programming" side of projects and have only dabbled on
> > the "design" side.  Whenever I've started a new project I've scoured the
> > internet for django templates that come complete with css, images, etc. and
> > always come up empty.
>
> > So I was thinking of making a "meta"-django project.  I could make a site
> > that allows designers to upload django-templates against a well defined set
> > of models, views, forms, etc.  Then users could switch between templates and
> > see how more "complex" examples function.  This would be useful for
> > designers to advertise their skills and for newbies to get a richer set of
> > functions.  Something akin to the CSS Zen Garden.
>
> > I'm looking for a collaborator or two ... or even just a few people to pick
> > their brains about some of the details.  I have some code in a git-hub
> > repositoryhttp://github.com/JudoWill/DjangoTemplateRepository/andI've got
> > about a dozen google-wave invitations if people would like to try
> > collaborating that way.  If you wouldn't mind either forwarding this to
> > anyone you think would be interested or posting it on your blog.
>
> > Thanks in advance,
> > Will

--

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: a request for some brain picking

2010-01-02 Thread Will Dampier
Thanks for the thoughts Dougal.  At the moment the only "managing" of
templates comes from uploading them through a form.  If you wanted to
change/fork them you'd have to create your own "design" and then re-
upload the modified template.

Right now my example templates are super simple HTML templates
(they're in the repository mentioned above).  If a design implements
then it will preferentially render the design's template over my own.

I do like the idea of people uploading templates that over-ride admin
templates.  It would make it more "plug-able" with current django
installations.  I could use many different models to to show all of
the possible "view-types" that the standard ModelAdmin allows.
Although I have a question about the usefulness of these templates.
(my understanding at least) Is that the admin site is supposed to be a
"no-mess" administration site that "covers all the bases" so the coder
doesn't have to worry about implementing it.  Do you think this would
be a useful resource for people creating "front-facing" templates
though?

The problem I see with a "wiki style" editing would be people
introducing malicious code which I end up unknowingly loading into
django and exposing myself and others to the whims of "bad people".
"Forking" a design would be pretty easy in implement, I could simply
copy the relevant files into a new one.

On Jan 2, 8:01 am, Dougal Matthews  wrote:
> How would you propose people edit and manage the templates?
>
> Do you follow a wiki style where everybody can edit others? or follow a VCS
> and allow forking of templates?
>
> I think it will be hard to find contributors since it will be hard to have a
> limited/standard template context that still remains a useful resource for
> all.
>
> Have you any thoughts about example templates? Perhaps a good place to start
> would be by creating custom admin templates as that context is defined by
> django already (pretty much) and then it would be useful and usable by
> anybody in real projects rather than scenarios.
>
> Dougal
>
> ---
> Dougal Matthews - @d0ugalhttp://www.dougalmatthews.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-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: a request for some brain picking

2010-01-02 Thread Will Dampier
 ... I do like the idea of having a handful of "standard django
plugables" like django-registration, django-cms, django-profiles, and
dozens of others ... the Django-Resources page would be a good place
to start.

Then designers could upload either a full "website layout" against all
of my, and the "plugable", views or simply a against a subset of the
"plugable" applications. If I "standardize" the blocks that the
designers are allowed to use, then for any missing templates I could
just implement my default template.  With some sort of trickery I
could even allow people to create mash-ups combining different
designs.

On Jan 2, 12:58 pm, Raja  wrote:
> IMO, it would be useful if we get standard templates for django
> libraries that are out there, like django-registration, django-
> profiles etc. Since the library offers the models and views, it would
> be helpful if the templates are also available. The developer could
> then take it and modify it to adapt to their website.
>
> Also, frameworks like Blueprint CSS (http://www.blueprintcss.org) make
> it much easier to start designing a layout by providing a pre-defined
> template , so its not all that difficult now, but blueprint could be
> one of the templates thats available in the original poster's library.
>
> -- Raja
>
> On Jan 2, 6:01 pm, Dougal Matthews  wrote:
>
> > How would you propose people edit and manage the templates?
>
> > Do you follow a wiki style where everybody can edit others? or follow a VCS
> > and allow forking of templates?
>
> > I think it will be hard to find contributors since it will be hard to have a
> > limited/standard template context that still remains a useful resource for
> > all.
>
> > Have you any thoughts about example templates? Perhaps a good place to start
> > would be by creating custom admin templates as that context is defined by
> > django already (pretty much) and then it would be useful and usable by
> > anybody in real projects rather than scenarios.
>
> > Dougal
>
> > ---
> > Dougal Matthews - @d0ugalhttp://www.dougalmatthews.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-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: a request for some brain picking

2010-01-02 Thread Will Dampier
Hmmm,

I wonder if I could make the entire site out of plugables.  Then
designers would have a well defined (or at least standard) set of
views and templates to program against.  It would also be useful for
newbies to find templates and designs for these commonly used apps.

I've created a simple voting thingy on "Moderator" at this url:
http://moderator.appspot.com/#15/e=125fbc&t=125fbd  Please suggest
and vote for the sort of apps you'd like to see included into a
repository.

On a side-note, I wonder if there's a way to create a "template-
loader" which will return the uploaded templates.  My current
implementation is to use a "r'(P.*?)/" in my urls.py to
determine which template to load.  This would be an annoying way to
implement it if I'm including pluggables.
Any thoughts?

On Jan 2, 2:43 pm, Dougal Matthews  wrote:
> 2010/1/2 Raja 
>
> > IMO, it would be useful if we get standard templates for django
> > libraries that are out there, like django-registration, django-
> > profiles etc. Since the library offers the models and views, it would
> > be helpful if the templates are also available. The developer could
> > then take it and modify it to adapt to their website.
>
> +1 making templates that are fitted for common apps (including contrib)
> would be great.
>
>
>
> > Also, frameworks like Blueprint CSS (http://www.blueprintcss.org) make
> > it much easier to start designing a layout by providing a pre-defined
> > template , so its not all that difficult now, but blueprint could be
> > one of the templates thats available in the original poster's library.
>
> +1 again - would help with standardisation of what is made

--

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: a request for some brain picking

2010-01-02 Thread Will Dampier
watching the pycon and django talks now (and it looks super cool) ...
but at least by what I see so far is that its trying to allow people
to download and create an "even more batteries included" type of
platform.  I'm hoping to create a repository of templates and designs
(more for learning and examples), not necessarily an integrated
platform.

On Jan 2, 2:02 pm, Jim White  wrote:
> If you don't already know about Pinax perhaps you should look 
> athttp://pinaxproject.com/.  They already provide some of this and (as a
> Pinax user) it would be nice to see some template compatibility.
> Unfortunately they are still sub 1.0 in their release but it looks
> like they have settled down a bit in their base.html and css.
>
> On Jan 2, 10:16 am, Will Dampier  wrote:
>
> >  ... I do like the idea of having a handful of "standard django
> > plugables" like django-registration, django-cms, django-profiles, and
> > dozens of others ... the Django-Resources page would be a good place
> > to start.
>
> > Then designers could upload either a full "website layout" against all
> > of my, and the "plugable", views or simply a against a subset of the
> > "plugable" applications. If I "standardize" the blocks that the
> > designers are allowed to use, then for any missing templates I could
> > just implement my default template.  With some sort of trickery I
> > could even allow people to create mash-ups combining different
> > designs.
>
> > On Jan 2, 12:58 pm, Raja  wrote:
>
> > > IMO, it would be useful if we get standard templates for django
> > > libraries that are out there, like django-registration, django-
> > > profiles etc. Since the library offers the models and views, it would
> > > be helpful if the templates are also available. The developer could
> > > then take it and modify it to adapt to their website.
>
> > > Also, frameworks like Blueprint CSS (http://www.blueprintcss.org) make
> > > it much easier to start designing a layout by providing a pre-defined
> > > template , so its not all that difficult now, but blueprint could be
> > > one of the templates thats available in the original poster's library.
>
> > > -- Raja
>
> > > On Jan 2, 6:01 pm, Dougal Matthews  wrote:
>
> > > > How would you propose people edit and manage the templates?
>
> > > > Do you follow a wiki style where everybody can edit others? or follow a 
> > > > VCS
> > > > and allow forking of templates?
>
> > > > I think it will be hard to find contributors since it will be hard to 
> > > > have a
> > > > limited/standard template context that still remains a useful resource 
> > > > for
> > > > all.
>
> > > > Have you any thoughts about example templates? Perhaps a good place to 
> > > > start
> > > > would be by creating custom admin templates as that context is defined 
> > > > by
> > > > django already (pretty much) and then it would be useful and usable by
> > > > anybody in real projects rather than scenarios.
>
> > > > Dougal
>
> > > > ---
> > > > Dougal Matthews - @d0ugalhttp://www.dougalmatthews.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-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: a request for some brain picking

2010-01-02 Thread Will Dampier
> watching the pycon and django talks now (and it looks super cool) ...
> but at least by what I see so far is that its trying to allow people
> to download and create an "even more batteries included" type of
> platform.  I'm hoping to create a repository of templates and designs
> (more for learning and examples), not necessarily an integrated
> platform.

After watching their two talks and playing around with the code I'm
quite impressed with their system.  In about 20 minutes I actually re-
implemented the entire site in pinax (and I may do the same with some
of my other projects).  At this point I'm not above throwing out my
crummy code if something better comes along ;).  It certainly
implements all of the "social features" that I was scratching my head
about.

All I really need to do is create a hook for rendering the arbitrary
templates.


On Jan 2, 3:55 pm, Will Dampier  wrote:
> watching the pycon and django talks now (and it looks super cool) ...
> but at least by what I see so far is that its trying to allow people
> to download and create an "even more batteries included" type of
> platform.  I'm hoping to create a repository of templates and designs
> (more for learning and examples), not necessarily an integrated
> platform.
>
> On Jan 2, 2:02 pm, Jim White  wrote:
>
> > If you don't already know about Pinax perhaps you should look 
> > athttp://pinaxproject.com/.  They already provide some of this and (as a
> > Pinax user) it would be nice to see some template compatibility.
> > Unfortunately they are still sub 1.0 in their release but it looks
> > like they have settled down a bit in their base.html and css.
>
> > On Jan 2, 10:16 am, Will Dampier  wrote:
>
> > >  ... I do like the idea of having a handful of "standard django
> > > plugables" like django-registration, django-cms, django-profiles, and
> > > dozens of others ... the Django-Resources page would be a good place
> > > to start.
>
> > > Then designers could upload either a full "website layout" against all
> > > of my, and the "plugable", views or simply a against a subset of the
> > > "plugable" applications. If I "standardize" the blocks that the
> > > designers are allowed to use, then for any missing templates I could
> > > just implement my default template.  With some sort of trickery I
> > > could even allow people to create mash-ups combining different
> > > designs.
>
> > > On Jan 2, 12:58 pm, Raja  wrote:
>
> > > > IMO, it would be useful if we get standard templates for django
> > > > libraries that are out there, like django-registration, django-
> > > > profiles etc. Since the library offers the models and views, it would
> > > > be helpful if the templates are also available. The developer could
> > > > then take it and modify it to adapt to their website.
>
> > > > Also, frameworks like Blueprint CSS (http://www.blueprintcss.org) make
> > > > it much easier to start designing a layout by providing a pre-defined
> > > > template , so its not all that difficult now, but blueprint could be
> > > > one of the templates thats available in the original poster's library.
>
> > > > -- Raja
>
> > > > On Jan 2, 6:01 pm, Dougal Matthews  wrote:
>
> > > > > How would you propose people edit and manage the templates?
>
> > > > > Do you follow a wiki style where everybody can edit others? or follow 
> > > > > a VCS
> > > > > and allow forking of templates?
>
> > > > > I think it will be hard to find contributors since it will be hard to 
> > > > > have a
> > > > > limited/standard template context that still remains a useful 
> > > > > resource for
> > > > > all.
>
> > > > > Have you any thoughts about example templates? Perhaps a good place 
> > > > > to start
> > > > > would be by creating custom admin templates as that context is 
> > > > > defined by
> > > > > django already (pretty much) and then it would be useful and usable by
> > > > > anybody in real projects rather than scenarios.
>
> > > > > Dougal
>
> > > > > ---
> > > > > Dougal Matthews - @d0ugalhttp://www.dougalmatthews.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-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: Can a ManyToManyField only shows certain records in an admin using edit_inline?

2007-08-01 Thread Will McCutchen

> Is there anyway that I can have the 'sandp' Field only
> show choices that are tied to that collection?

Try using the limit_choices_to argument to ManyToManyField:
http://www.djangoproject.com/documentation/model-api/#many-to-many-relationships

Hope this helps,


Will.


--~--~-~--~~~---~--~~
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: Problem using external CSS file with template

2007-08-21 Thread Will McCutchen

Hi,

On Aug 21, 1:44 pm, arelenas <[EMAIL PROTECTED]> wrote:
> I've set URLConf as described 
> athttp://www.djangoproject.com/documentation/0.96/static_files/,
> but still nothing. It finds CSS file but styles won't apply.

What does your URLConf look like?  What is the URL you are using to
link to the CSS file in your template (ie, what replaces "XXX" in
)?


Will.


--~--~-~--~~~---~--~~
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: Configure Mod_Python fo Django on Apache server on Ubuntu

2008-04-06 Thread Will Boyce

Assuming your django project (mysite) is in /home/webmaster/
public_html/django/ then you'll want a trailing "/" in your
PythonPath.

Hope this helps.

On Apr 5, 9:53 pm, HangingClowns <[EMAIL PROTECTED]> wrote:
> I should have the latest versions available for Apache and mod_python
> cause I just put those onto my server about 2 weeks ago. I'm having
> trouble understanding how to edit the Apache config file for Django. I
> currently use the code snippet below for my settings in Apache. And
> this is what the error looks like:
>
> http://67.207.140.149/mysite/
>
> Can someone help me out?
>
> I have started a project in the /home/webmastr/public_html/django
> called mysite, cause I'm following the tutorial on Djangoproject.org.
> I did not find their instructions for configuring modpython to be very
> helpful for me. So, back to subject, within that django folder, is a
> folder called "mysite" with all of the beginning project python .py
> files.
>
>  
>         SetHandler python-program
>         PythonHandler django.core.handlers.modpython
>         SetEnv DJANGO_SETTINGS_MODULE mysite.settings
>         PythonDebug On
>         PythonPath "['/home/webmastr/public_html/django'] + sys.path"
> 
--~--~-~--~~~---~--~~
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: Navigation components

2008-06-03 Thread Will Boyce

I am also in a very similar situation to you, Will (nice name btw).

I have a 2 level hierarchy in an ajax-y fashion.. It's easier to show
than describe: http://beta.willboyce.com/blog (if it fails to load and
you care enough, try again in a few mins - "beta" ;-))

In order to mark the current section/subsection I wrote all my views
to expect an "extra_context" parameter (meaning generic views would
work), which contains "section" and "subsection" vars - these are
added by middleware (process_view()) - and the header is build in a
base.html using pretty simple templating:


{% for s in sections %}
{{ s.title }}
{% endfor %}


I have a nav app which has a Section model and some ajax views, which
I could see no way to do but hard code (if section=x and
subsection=y... hardcoded sections/subsections)

I don't know - it works but it doesn't feel like the most elegant
solution. Especially with the middleware/adding context to views (this
is my first django project btw!)

Hope this helped.. And any comments would be more than welcome :-)

Regards, Will Boyce

On Jun 3, 8:35 pm, Will <[EMAIL PROTECTED]> wrote:
> Thanks for your replies, chaps.
>
> I need to mull this over, but I think I see what you're getting at
> (using template inheritance). I've realised the breadcrumbs should be
> easy (use Super to add to the breadcrumb section I suppose).
> The bit I don't see is how you get the info about section navigation
> into the context - is is hard-coded into the view? This is what I'd
> like to avoid.
>
> Cheers
>
> Will
--~--~-~--~~~---~--~~
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: django + google appengine?

2008-06-03 Thread Will Boyce

Google discuss this at length.

http://code.google.com/p/google-app-engine-django/ would be a good  
starting place I guess. There may be more in the GAE Docs

Regards, Will Boyce

u: http://willboyce.com
e: [EMAIL PROTECTED]

On 3 Jun 2008, at 22:02, [EMAIL PROTECTED] wrote:

>
> i, once i have learned more about django, will build a prety big
> application and want to host it somewhere for free.
>
> google appengine seems like a good place to start, then i dont have to
> get my own servers and stuff.
>
> is this easy integrateable? or doesnt google appengine and django work
> together?
> >


--~--~-~--~~~---~--~~
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: django + google appengine?

2008-06-03 Thread Will Boyce

oops, http://code.google.com/appengine/articles/django.html was the  
link I should've given you

Regards, Will Boyce

u: http://willboyce.com
e: [EMAIL PROTECTED]

On 3 Jun 2008, at 22:02, [EMAIL PROTECTED] wrote:

>
> i, once i have learned more about django, will build a prety big
> application and want to host it somewhere for free.
>
> google appengine seems like a good place to start, then i dont have to
> get my own servers and stuff.
>
> is this easy integrateable? or doesnt google appengine and django work
> together?
> >


--~--~-~--~~~---~--~~
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: complaint about production db when running unit tests

2008-06-18 Thread Will Larson

Andrew,

Running 'manage.py test' will create new tables, but not a new  
database. It can't create a new database, since it doesn't know what  
settings to use for that new database. However, your data stored in  
your database won't get overwritten since you will be using a  
temporary table.

Best,
Will

On Jun 19, 2008, at 7:16 AM, Andrew D. Ball wrote:

>
> Good afternoon.
>
> I thought that unit tests run by 'manage.py test' create
> a test db that is separate from the production database
> by default, prepending 'test_' to the database
> name specified by settings.DATABASE_NAME or using
> settings.TEST_DATABASE_NAME for the name of the
> new database.
>
> I'm using Django 0.96.1, and 'python manage.py test'
> will complain unless the production database
> is created and I've run 'manage.py syncdb'.
>
> Any idea why?
>
> Peace,
> Andrew
> -- 
> ===
> Andrew D. Ball
> [EMAIL PROTECTED]
> Software Engineer
> American Research Institute, Inc.
> http://www.americanri.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
-~--~~~~--~~--~--~---



Re: Django on apache and mod_python.... and problems

2008-06-21 Thread Will Larson
Hi,

> The summary of error messages is this:
>
>> AttributeError: 'module' object has no attribute 'blog'
>
> I've made sure that /papastudio/blog has __init.py__, and that it's
> listed in INSTALLED_APPS (which is logical since the site actually
> works if I ./manage.py runserver).

Did you follow the mod_python deploy instructions? There are a few  
things that may be happening.

1. The file needs to be '__init__.py', not '__init.py__', but I think  
that is probably just a typo in this email.
2. Make sure you have __init__.py in both `/papastudio/` and `/ 
papastudio/blog/`.
3. Is the base import (depending on what the entry in your  
INSTALLED_APPS looks like, if its `papastudio.blog` then it would be  
`papastudio`) in the Python path for your mod_python deploy? You will  
probably need to explicitly add it like in the instructions linked  
above. Your deploy will look something like this:

 
 SetHandler python-program
 PythonHandler django.core.handlers.modpython
 SetEnv DJANGO_SETTINGS_MODULE papastudio.settings
 PythonDebug Off
 PythonPath "['/path/to/papastudio'] + sys.path"
 

>
> I've left the site in debug mode, so that I can see what's going on,
> but the errors are the same if I set debug to False.
>

Thats because they are being caught by mod_python, and not by Django.  
To turn it off change `PythonDebug On` to `PythonDebug Off` in your  
mod_python config file.

Best of luck,
Will



--~--~-~--~~~---~--~~
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: Unable to upload PNG's

2008-06-23 Thread Will Larson
Julian,

This is a PIL issue that appears to be biting a lot of people.  
Googling for "PIL PNG problem" will  help, but this link might be a  
good starting point.

Best,
Will

On Jun 23, 2008, at 6:02 PM, jurian wrote:

>
> I am currently getting an error when I attempt to upload a PNG image
> from the admin side.
>
> Error: Upload a valid image. The file you uploaded was either not an
> image or a corrupted image.
>
> There is nothing wrong with the image, and I've made sure that my PIL
> is setup correctly.
>
> 
> PIL 1.1.6 BUILD SUMMARY
> 
> version   1.1.6
> platform  linux2 2.5.2 (r252:60911, Mar 27 2008, 15:17:32)
>   [GCC 4.1.3 20070929 (prerelease) (Ubuntu
> 4.1.2-16ubuntu2)]
> 
> *** TKINTER support not available
> --- JPEG support ok
> --- ZLIB (PNG/ZIP) support ok
> --- FREETYPE2 support ok
> ----
>
> Any clues will be appreciated, thanks.
> >


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



Re: [Fwd: Custom field in JSON serializer]

2008-06-28 Thread Will Larson

Ganesh,

You'll need to create your own serializer. You can do this by  
subclassing django.core.serializers.base (or perhaps you might  
subclass the json one, there are a number of ways to skin the cat  
here), and then registering it with  
django.core.serializers.register_serializer, which is used like this:

 from django.core.serializers import register_serializer, serialize
 register_serializer("extra_json",  
"myapp.serializer.myjsonserializer")
 objs = MyModel.objects.all()
 data = serialize('extra_json', objs)

Look around the django.core.serializers files at the existing  
serializers for the details of how to implement your subclass.

Best of luck,
Will


On Jun 28, 2008, at 7:03 PM, M.Ganesh wrote:

>
>  people who asked after me got their answers, sometimes
> within 15 minutes. I've not got any answers 
>
> Should I reword my query?
>
> Regards Ganesh
>
>
>  Original Message 
>
> Hi All,
>
> I picked up this sample code from django documentation:
>
> from django.core import serializers
> data = serializers.serialize('xml', SomeModel.objects.all(),
> fields=('name','size'))
>
> How do I extend this to do the following:
>
> data = serializers.serialize('xml', SomeModel.objects.all(),
> fields=('name','size', '__unicode__'))
>
> Thanks in advance
>
> Regards Ganesh
>
>
>
>
> >


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



Validations and error messages

2008-07-12 Thread Will Rocisky

Hi,

This is my second hour with django. I have been working Rails but now
I am learnign some django too.

I wonder how do you validate numeric, alphabetic, mix, special
characters data before calling save() ?

And do you get any return after calling save()? I didnt get any on
Shell.
I actually want to redirect the user based on validations.

--~--~-~--~~~---~--~~
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: Path/Environment problem (may be Mac-specific)

2007-04-04 Thread Will McCutchen

On Apr 4, 1:16 pm, "Richard Blumberg" <[EMAIL PROTECTED]>
wrote:
> ImportError: No module named django.db
>
> I can't figure out why it works from the standard python shell but not from
> within BBEdit. Perhaps this is a question for the BBEdit list rather than
> the Django list, but if anyone here can point me in a helpful direction, I
> would be most grateful.

It looks to me like BBEdit must be using a different PYTHONPATH than
the standard Python shell.  Which, I think, would make this a question
for the BBEdit list.

Sorry this isn't a really helpful answer.  Maybe someone else will
know a better solution.


Will.


--~--~-~--~~~---~--~~
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: def __str__(self) error in tutorial part 1

2007-10-03 Thread Will McCutchen

Hi,

On Oct 2, 1:18 pm, rhett <[EMAIL PROTECTED]> wrote:
> 1) I am working in TextMate and copied/pasted below code. In TextMate
> the "def __str__(self)" is not indented from the pub_date line - it's
> the same indent.

I too use TextMate to do a lot of my Python development.  It
consistently over-indents my code when I copy and paste.  It's trying
to be helpful and "intelligently" indent the pasted code, but the
smart indentation doesn't seem to work very well with Python.

> I know indents are important - is there a way to set
> up TextMate to show correct indentation?

If you highlight the code that you want unindented, you can use
Command-[ to decrease the indentation by one level.

Hope this helps,


Will.


--~--~-~--~~~---~--~~
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: Request in a template

2007-11-21 Thread Will Larson


> I have an parameter in my querystring which i would like to access in
> a template, fx:
>
> ---
> 
> ---
>


http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context- 
processors/

Shows you how to do just that.

But, I would recommend handling that a bit different. Specifically in  
your view mapping the url you want to return to to a variable in the  
template ("return_url", etc), so that in your template you'd have

 

In my mind this is meaningful because it preserves the distinction  
between the template deciding how to present information, and the  
views deciding what information to present. Also you would likely  
want to do some preprocessing on the url to make sure its a valid  
value (also, to prevent abject failure in a situation where there was  
no get request, or the get request did not have the url field. If  
only input was sanitary...), which you couldn't do in the template,  
but is quite doable in the views file.

This may seem like a needless distinction, and it is... as long as  
what you are doing isn't important or particularly large.

--~--~-~--~~~---~--~~
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: currently online users?

2007-01-23 Thread Will McCutchen



On Jan 23, 1:18 pm, "Rob Hudson" <[EMAIL PROTECTED]> wrote:
> I don't have an answer but some thoughts...

Me, too...

> I'd probably go with the 3rd option.  But if that didn't work, maybe
> look at writing my own session middleware that added new column to the
> django_session table that was a last_modified field.

I would add option #5:  Write a custom middleware component to update a
last_accessed attribute for logged in users on every request.

http://www.djangobook.com/en/beta/chapter16/


Will.


--~--~-~--~~~---~--~~
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: Foreign key filter question

2014-01-29 Thread Will A
Try
target_name_name__icontains='foo' or update the foreign key definition.



On Wed, Jan 29, 2014 at 5:08 PM, Larry Martell wrote:

> I have a table that has these 2 foreign keys:
>
> target_name = models.ForeignKey(Target)
> wafer = models.ForeignKey(Wafer)
>
> Both Target and Wafer are defined the same:
>
> name = models.CharField(max_length=40, db_index=True, unique=True)
>
> When filtering by wafer I can do this:
>
> wafer__name__icontains='foo'
>
> But when I try to do the same with target, if I do this:
>
> target__name__icontains='foo'
>
> I get:
>
> FieldError Cannot resolve keyword 'target' into field. And in the
> choices it shows:
>
> target_name
>
> And if I do:
>
> target_name__icontains='foo'
>
> I get:
>
> Related Field has invalid lookup: icontains
>
> How can I do foreign key filtering using icontains on this field?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CACwCsY6%3DAOjhYssUYWNQDk-txNvZTfv4RQOZeCSd%2Bb1qQ0NvSA%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK8f%2Bfr2DPpqwh7j4HBZ8ia-YfmpYTTduLzKqbTeNnvz%3DDKd5g%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Templates and URL Mappings

2018-04-02 Thread Will Burchell
Hi all, I'm having some trouble understanding fairly basic URL mappings and 
how they rout through to templates. I have an app "stock" which is 
registered in my base admin.py. I have three classes in my app, 
stock\models.py listed below:

from django.db import models


class Supplier(models.Model):
supplierName = models.CharField(max_length=64, default='')
def __str__(self):
return self.supplierName


class Stock(models.Model):
stockCode = models.CharField(max_length=32, default='null')
stock_supplier = models.ManyToManyField(Supplier, through=
'SupplierStock') # Populated automatically
stockDescription = models.CharField(max_length=128)
retailPrice = models.CharField(max_length=16, default='')

def __str__(self):
return self.stockCode + '; ' + self.stockDescription + ' @£' + self.
retailPrice

#Quote
class SupplierStock(models.Model):
stock = models.ForeignKey(Stock, on_delete=models.CASCADE)
supplier = models.ForeignKey(Supplier, on_delete=models.CASCADE)
supplierCode = models.CharField(max_length=32)
supplierPrice = models.CharField(max_length=16)
quoteRef = models.CharField(max_length=32, default="")
unitSize = models.PositiveSmallIntegerField(default=1)

def __str__(self):
return self.supplierCode + ', £' + self.supplierPrice + ' Per ' + 
str(self.unitSize) + '; ' + self.quoteRef
  
The app is a basic stock record for stock items, suppliers, and quotes as 
per "SupplierStock". I am playing around trying to get the individual 
classes in my stock\models.py to map to templates in 
"stock\templates\stock\" but am only having partial success. I can get my 
index.html and details.html to display a list of stock Items, and details 
for the stock items respectfully, but am having trouble displaying similar 
results for the supplier.html template and supplierdetail.html.  Here's my 
code for stock\urls.py

from django.conf.urls import url
from . import views

app_name = 'stock' # Referenced by template, ie  item in index.html

urlpatterns = [
# /stock/
url(r'^$', views.index, name="index"),
# /stock/nnn/
url(r'^(?P[0-9]+)/$', views.detail, name="detail"),
# /stock/supplier
url(r'^supplier', views.supplier, name="supplier"),
# /stock/supplier/nnn/
url(r'^supplier/(?P[0-9]+)/$', views.supplierdetail, name=
"supplierdetail"),
]

The stock\views.py code:


from django.shortcuts import render, get_object_or_404
from .models import Stock, Supplier, SupplierStock


def index(request):
all_stock = Stock.objects.all()
return render(request, 'stock/index.html', {'all_stock' : all_stock})

def detail(request, stock_id):
stock = get_object_or_404(Stock, id=stock_id)
return render(request, 'stock/detail.html', {'stock' : stock})

def supplier(request):
all_supplier = Supplier.objects.all()
return render(request, 'stock/supplier.html', {'all_supplier' : 
all_supplier})

def supplierdetail(request, supplier_id):
supplier = get_object_or_404(Supplier, id=supplier_id)
return render(request, 'stock/supplierdetail.html', {'supplier' : 
supplier})


The code for stock\templates\stock\index.html:

{% if all_stock %}
Stock list

{% for stock in all_stock %}
{{ stock.stockCode 
}}; {{ stock.stockDescription }}
{% endfor %}

{% else %}
No stock found
{% endif %}

...and a simple stock\templates\stock\detail.html that shows detail for the 
stock item as expected:

{{ stock }}

I thought I would be able to get away with copying most of the code to 
achieve similar results for the supplier and supplierdetail templates. My 
stock\supplier.html correctly displays a list of links to suppliers, but 
the links do not work, the it just stays on the page. Here's what I have 
for stock\templates\stock\supplier.html

{% if all_supplier %}
Supplier list

{% for supplier in all_supplier %}
{{ 
supplier.supplierName }}
{% endfor %}

{% else %}
No Supplier found
{% endif %}

...and for stock\templates\stock\supplierdetail.html

Supplier details here
{{ supplier }}

As mentioned, the index.html and detail.html templates render fine, but the 
links in supplier.html are dead. I'll be trying to connect the models up in 
one template to display individual quotes from suppliers but am having 
trouble getting past this step. The project is using Django 1.11.8 and 
Python 3.6.2 on Windows 8.1 Pro.

I should also mention that the Django admin page displays all the 
information I'm trying to display fine. Thanks for taking the time to read 
my issue, and I'll be very grateful for any assistance offered!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Vi

Re: Templates and URL Mappings

2018-04-03 Thread Will Burchell
Daniel, thank you so much! 

I had been eyeing my regex with suspicion by was looking at the wrong 
pattern. Many thanks again, all appeas to be working fine now :)

On Monday, 2 April 2018 12:27:56 UTC+1, Daniel Roseman wrote:
>
> On Monday, 2 April 2018 12:00:31 UTC+1, Will Burchell wrote:
>
> 
>  
>
>> from django.conf.urls import url
>> from . import views
>>
>> app_name = 'stock' # Referenced by template, ie  item in index.html
>>
>> urlpatterns = [
>> # /stock/
>> url(r'^$', views.index, name="index"),
>> # /stock/nnn/
>> url(r'^(?P[0-9]+)/$', views.detail, name="detail"),
>> # /stock/supplier
>> url(r'^supplier', views.supplier, name="supplier"),
>> # /stock/supplier/nnn/
>> url(r'^supplier/(?P[0-9]+)/$', views.supplierdetail, 
>> name="supplierdetail"),
>> ] 
>>
>
>
> Firstly, as a clarification, URLs don't map to templates at all; they map 
> to views, and views may or may not render templates. But you do seem to 
> know this.
>
> Your problem however is simply to do with regexes; you don't terminate 
> your supplier pattern, so it matches everything beginning with "supplier". 
> It should be:
>
> url(r'^supplier$', views.supplier, name="supplier"),
>
> or use the new path syntax in Django 2.0:
>
> path('supplier', ...)
>
> -- 
> DR.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/29366cc5-07ef-4239-aa1d-648069961eda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Upload multiple files at once

2017-02-11 Thread Will Treston
Hey,

im trying to upload multiple files in one go and I just cant get it to work.

Any help would be appreciated.
Thanks,
-Will

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/29149c9f-0f68-4834-8035-297a9d537607%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


NoReverseMatch when trying to use get_absolute_url with custom template tag

2017-03-29 Thread Will Holmes


I am making a calendar app which has a custom template tag that takes the 
python HTML template function and overlays objects from the Events model on 
the correct days. I am trying to get the displayed objects to have a link 
directly to an object detail/edit view and am trying to use 
get_absolute_url and to reverse render this view. This is necessary as the 
custom template tag doesn't load correctly if I try to hardcode {% url %} 
template 
tags into it for each event via a for loop. I have spent some hours looking 
through stack overflow questions with no luck and have even changed my 
reverse to the object ID rather than the title of the event. I am hoping 
this is just a small thing that I have overlooked but no sure.


view:

def home(request, month=None, year=None):
if month == None:
_date = datetime.now()
else:
_date = date(int(year), int(month), 1)
title = "%s, %s" % (_date.strftime("%B"), _date.strftime("%Y"))

return render(request, 'calendar.html', calendar(_date, title))


url:

app_name = 'cal'
urlpatterns = [
url(r'^$', views.home, name='home'),
url(r'^newevent/$', views.newEvent, name='newevent'),
url(r'^(?P\d+)$/', views.viewEvent, name='viewevent'),
url(r'^(?P\d+)/(?P\d+)$', views.home, name='another-month')]


HTML:


  {% load calendarify %}
  {% calendarify year month event_list %}



Template tag relevant function:

def formatday(self, day, weekday):
if day != 0:
cssid = self.cssclasses[weekday]
cssclass = "daybox"
if date.today() == date(self.year, self.month, day):
cssid += ' today'
if day in self.events:
cssid += ' filled'
body = ['']
for event in self.events[day]:
body.append('')
body.append('' % event.get_absolute_url())
body.append(esc(event.title))
body.append('')
body.append('')
return self.day_cell(
cssclass, cssid, '%d %s' % (
day, ''.join(body)))
return self.day_cell(
cssclass, cssid, '%d' 
% (day))
return self.day_cell('nodaybox', 'noday', ' ')


Model:

class Events(models.Model):
...

def get_absolute_url(self):
return reverse('cal:viewEvent', args=[str(self.id)], current_app='cal')


Sorry about the load of code posted. Any chance anyone knows what might 
have caused this issue?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/aae357a0-84a7-46bd-a93d-4aac61f352c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: NoReverseMatch when trying to use get_absolute_url with custom template tag

2017-03-30 Thread Will Holmes
Oh yeah i see.

Brilliant sorted it! Thanks for your help Melvyn.

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


Re: safe perfect and reliable app for verification email

2017-04-16 Thread Willian Will
Hey, you can user javasript for that, thus You dont need use ajax or 
anything for retrieve confirmation about email is correct or no , but you 
need confirm about the email already exists in database ?


sábado, 15 de Abril de 2017 às 09:22:21 UTC-3, shahab emami escreveu:
>
> hello
> I want to verify user's email while user is registering  .
>
> can you introduce me a few safe perfect  and reliable app for verification 
> email?
>
> thanks
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9e07bab1-2bdc-4056-9a6e-29a418f932d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error:Microsoft visual c++ 14.0 is required

2017-04-16 Thread Willian Will

hey , download and install 
that https://www.microsoft.com/en-us/download/details.aspx?id=48145
domingo, 16 de Abril de 2017 às 09:35:06 UTC-3, Ronnie escreveu:
>
> I have installed Microsoft visual c++ 14.0 then also it is showing error 
> as Microsoft visual c++ 14.0 is required. Please help me.I need a 
> solution...
>

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


Using Django with groupby

2017-04-20 Thread Will Holmes


Hi guys,


I am using django to develop a calendar web app where users can create events 
that are then displayed on a month by month view.


I have written a custom template tag that takes Python's HTMLCalendar 
formatmonth function and overlays events that are on that day. 


It is currently set up to take the start date of the event directly from each 
event and then use groupby to group each event by the day of the month in a 
dictionary. These can then be overlaid on the calendar. This, however, is not 
particularly useful if an event occurs over multiple days. 


I want to find a way of taking each of the days the event occurs over, start 
date to end date, before returning a similar dictionary. However, I cannot seem 
to get this to work whichever way I try it. Here is the group_by_day function 
that currently groups the events by start date:


#Here is where the code groups events for the relevant month day 
def group_by_day(self, events):
field = lambda event: event.start_date.day
return dict(
[(day, list(items)) for day, items in groupby(events, field)]
)


Can anyone suggest a way round this problem?


If you need any more information please let me know. The project can be viewed 
in entirety at https://github.com/Willrholmes01/organiser.


Below is the entire template tag:


register = template.Library()

def do_month_calendarify(parser, token):
# Take the tag input from the template and format
# Template syntax is {% calendarify year month %}
try:
tag_name, year, month, event_list = token.split_contents()
except ValueError:
raise template.TemplateSyntaxError(
"%r tag requires three arguments" % token.contents.split()[0]
)
return CalendarifyNode(year, month, event_list)

class CalendarifyNode(template.Node):

def __init__(self, year, month, event_list):
try:
self.year = template.Variable(year)
self.month = template.Variable(month)
self.event_list = template.Variable(event_list)
except ValueError:
raise template.TemplateSyntaxError

def render(self, context):
try:
my_year = self.year.resolve(context)
my_month = self.month.resolve(context)
my_event_list = self.event_list.resolve(context)
cal = EventCalendar(my_event_list)
return cal.formatmonth(
int(my_year), int(my_month))
except ValueError:
return "%s, %s, %s" % (my_month, my_year, my_event_list)

class EventCalendar(HTMLCalendar):
# Use Python's HTMLCalendar and put user events over top
def __init__(self, events):
super(EventCalendar, self).__init__()
self.events = self.group_by_day(events)

def formatday(self, day, weekday):
if day != 0:
cssid = self.cssclasses[weekday]
cssclass = "daybox"
if date.today() == date(self.year, self.month, day):
cssid += ' today'
if day in self.events:
cssid += ' filled'
body = ['']
for event in self.events[day]:
body.append('')
body.append(''
% (event.id, event.get_absolute_url()))
body.append(esc(event.title))
body.append('')
body.append('')
return self.day_cell(
cssclass, cssid, '%d %s' 
% (
day, ''.join(body)))
return self.day_cell(
cssclass, cssid, '%d' % (day))
return self.day_cell('nodaybox', 'noday', ' ')

def formatmonth(self, year, month):
self.year, self.month = year, month
return super(EventCalendar, self).formatmonth(year, month)

#Here is where the code groups events for the relevant month day 
def group_by_day(self, events):
field = lambda event: event.start_date.day
return dict(
[(day, list(items)) for day, items in groupby(events, field)]
)

def day_cell(self, cssclass, cssid, body):
return '%s' % (cssclass, cssid, body)

register.tag('calendarify', do_month_calendarify)






-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/775bc7f8-46e3-4fb2-9581-35d05ceb812e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using Django with groupby

2017-04-21 Thread Will Holmes
Fixed this by just not using groupby. So far I just have a slightly 
long-winded work around that formats the data in the same way as groupby 
but includes all days in in between, and including, the start date and end 
date.

def group_by_day(self, events, month):
return_dict = {}
for event in events:
if event.end_date != None:
number_days = event.end_date - event.start_date
day_range = [event.start_date + timedelta(
days=i) for i in range(number_days.days + 1)]
for date in day_range:
if date.month == month:
if date.day in return_dict:
return_dict[date.day].append(event)
else:
return_dict[date.day] = [event]
else:
if event.start_date.day in return_dict:
return_dict[event.start_date.day].append(event)
else:
return_dict[event.start_date.day] = [event]
return return_dict



On Thursday, April 20, 2017 at 4:35:36 PM UTC+1, Will Holmes wrote:
>
> Hi guys,
>
>
> I am using django to develop a calendar web app where users can create events 
> that are then displayed on a month by month view.
>
>
> I have written a custom template tag that takes Python's HTMLCalendar 
> formatmonth function and overlays events that are on that day. 
>
>
> It is currently set up to take the start date of the event directly from each 
> event and then use groupby to group each event by the day of the month in a 
> dictionary. These can then be overlaid on the calendar. This, however, is not 
> particularly useful if an event occurs over multiple days. 
>
>
> I want to find a way of taking each of the days the event occurs over, start 
> date to end date, before returning a similar dictionary. However, I cannot 
> seem to get this to work whichever way I try it. Here is the group_by_day 
> function that currently groups the events by start date:
>
>
> #Here is where the code groups events for the relevant month day 
> def group_by_day(self, events):
> field = lambda event: event.start_date.day
> return dict(
> [(day, list(items)) for day, items in groupby(events, field)]
> )
>
>
> Can anyone suggest a way round this problem?
>
>
> If you need any more information please let me know. The project can be 
> viewed in entirety at https://github.com/Willrholmes01/organiser.
>
>
> Below is the entire template tag:
>
>
> register = template.Library()
>
> def do_month_calendarify(parser, token):
> # Take the tag input from the template and format
> # Template syntax is {% calendarify year month %}
> try:
> tag_name, year, month, event_list = token.split_contents()
> except ValueError:
> raise template.TemplateSyntaxError(
> "%r tag requires three arguments" % token.contents.split()[0]
> )
> return CalendarifyNode(year, month, event_list)
>
> class CalendarifyNode(template.Node):
>
> def __init__(self, year, month, event_list):
> try:
> self.year = template.Variable(year)
> self.month = template.Variable(month)
> self.event_list = template.Variable(event_list)
> except ValueError:
> raise template.TemplateSyntaxError
>
> def render(self, context):
> try:
> my_year = self.year.resolve(context)
> my_month = self.month.resolve(context)
> my_event_list = self.event_list.resolve(context)
> cal = EventCalendar(my_event_list)
> return cal.formatmonth(
> int(my_year), int(my_month))
> except ValueError:
> return "%s, %s, %s" % (my_month, my_year, my_event_list)
>
> class EventCalendar(HTMLCalendar):
> # Use Python's HTMLCalendar and put user events over top
> def __init__(self, events):
> super(EventCalendar, self).__init__()
> self.events = self.group_by_day(events)
>
> def formatday(self, day, weekday):
> if day != 0:
> cssid = self.cssclasses[weekday]
> cssclass = "daybox"
> if date.today() == date(self.year, self.month, day):
> cssid += ' today'
> if day in self.events:
> cssid += ' filled'
> body = ['']
> for event in self.events[day]:
> body.append('')
> body.append(''
> % (event.id, event.get_absolute_

NoReverseMatch

2017-04-28 Thread Will Holmes
Hey all,

Can anyone tell me the (probably quite obvious) reason my reverse match 
isn't working?

Template:

  


Url:
url(r'^events/(\d+)/delete_event$', views.delete_event, 
name='delete_event'),

View:
def delete_event(request, id):
Events.objects.filter(id=id).delete()
return redirect("cal:home")

Also, if anyone can tell me a good way to get my delete button I'd be very 
grateful. 

Cheers,

Will

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d4dfea2a-2e59-4665-9a52-67af52e6476c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: NoReverseMatch

2017-04-28 Thread Will Holmes
#x27; not found. 1 pattern(s) tried: 
['cal/events/(\\d+)/delete_event$']


cal:urls:
from django.conf.urls import url, include
from django.contrib import admin
from cal import views, models

app_name = 'cal'
urlpatterns = [
url(r'^$', views.home, name='home'),
url(r'^newevent/$', views.newevent, name='newevent'),
url(r'^events/(\d+)/', views.viewevent, name='viewevent'),
url(r'^(?P\d+)/(?P\d+)$', views.home, 
name='another-month'),
url(r'^events/(\d+)/delete_event$', views.delete_event, 
name='delete_event'),
]


urls:
from django.conf.urls import url, include
from cal import urls as cal_urls
from accounts import urls as accounts_urls

urlpatterns = [
url(r'^cal/', include(cal_urls, namespace="cal")),
url(r'^accounts/', include(accounts_urls)),
]


Let me know if you need anything else. :)


Cheers,


Will


 Friday, April 28, 2017 at 10:01:33 PM UTC+1, James Schneider wrote:

> Hey all,
>
> Can anyone tell me the (probably quite obvious) reason my reverse match 
> isn't working?
>
>
> Post the traceback and urls.py files. You're referencing the 'cal' name 
> space, so the single URL line you posted is not enough to make a 
> determination.
>
> -James
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/216445d5-247a-42ee-9689-000d4d1daaca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Effecient Text Search

2020-03-14 Thread Will Meyers
Hi all,

Just a quick question. I'm working on a general search function for my 
application and just wanted your opinions before I do any sort of 
benchmarking.

Right now I have a PostgreSQL database with a table (model) which includes 
a title column and summary column (both charfields).

Would it be more efficient to call:

v = SearchVector(title, weight='A') + SearchVector(summary, weight='A')
results = MyModel.objects.annotate(rank=SearchRank(v, 'my 
query')).filter(rank__gte=0.5)

Or should I join the title and summary (i.e. create a new column 
title_summary within the model which just concats them) and do the search 
on that with:

v = SearchVector(title_summary, weight='A')
results = MyModel.objects.annotate(rank=SearchRank(v, 'my 
query')).filter(rank__gte=0.5)

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7c884279-de2e-42ad-a18b-2f2e49315954%40googlegroups.com.


Re: how to calculate appreciation and depreciation with the use of forms

2020-03-21 Thread Will Meyers
We would need more information if you're having a specific issue, but 
general if I were building something of that sort I would be using celery 
<http://www.celeryproject.org/> to perform all the calculations. 

Form data can be easily serialized and passed to the task queue and the 
results can easily be retrieved. I'd start with this guide if you're new: First 
Steps with Django and Celery
<https://docs.celeryproject.org/en/latest/django/first-steps-with-django.html>

On Saturday, March 21, 2020 at 2:32:36 PM UTC-4, Ernest Thuku wrote:
>
> Hello guys am having troubles on how I will be able to perform 
> calculations in an asset management application. Is there any way I can do 
> this or anyone has ever encountered this? I will be glad for your 
> assistance.
>

-- 
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/642c188b-796e-46d1-abb0-9421f4636982%40googlegroups.com.


Re: Custom login in django

2020-03-30 Thread Will Meyers
We'd need more info, but most likely the actual token is not being sent to
the template properly. See this
<https://stackoverflow.com/questions/43410287/django-csrf-token-missing-or-incorrect-error-403>
thread for suggestions.

On Mon, Mar 30, 2020 at 11:18 AM Kushal Neupane  wrote:

> Forbidden (403)
>
> CSRF verification failed. Request aborted.
> Help
>
> Reason given for failure:
>
> CSRF token missing or incorrect.
>
>
> In general, this can occur when there is a genuine Cross Site Request
> Forgery, or when Django's CSRF mechanism
> <https://docs.djangoproject.com/en/3.0/ref/csrf/> has not been used
> correctly. For POST forms, you need to ensure:
>
>- Your browser is accepting cookies.
>- The view function passes a request to the template's render
>
> <https://docs.djangoproject.com/en/dev/topics/templates/#django.template.backends.base.Template.render>
>method.
>- In the template, there is a {% csrf_token %} template tag inside
>each POST form that targets an internal URL.
>- If you are not using CsrfViewMiddleware, then you must use
>csrf_protect on any views that use the csrf_token template tag, as
>well as those that accept the POST data.
>- The form has a valid CSRF token. After logging in in another browser
>tab or hitting the back button after a login, you may need to reload the
>page with the form, because the token is rotated after a login.
>
> You're seeing the help section of this page because you have DEBUG = True
> in your Django settings file. Change that to False, and only the initial
> error message will be displayed.
>
> You can customize this page using the CSRF_FAILURE_VIEW setting.
>
> [image: Capture.PNG]
>
>
> --
> 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/7de9d86d-5607-43c5-8462-185a04bcc648%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/7de9d86d-5607-43c5-8462-185a04bcc648%40googlegroups.com?utm_medium=email&utm_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/CACCQDfDo64nJnPgMG%3DdX93wHAbkWUyjyTTtXQdptPJn6jLZQzg%40mail.gmail.com.


Custom Permissions of Django Materialized View

2020-06-10 Thread Will Meyers
Hi all,

I'm building an application that uses Django Rest Framework and Django 
Guardian. I have to implement a permissions system such that when a user 
requests data from a materialized view, I need to omit certain rows from 
the returned queryset based on the user's group. 

For example, if my app contains 5 models:

   - User Model
   - User Group Model
   - Source Model
   - Article Model (with manytomany to Source Model)
   - Article Materialized View (consists of a flat table with an array 
   field for sources

If a user searches for articles, but because they belong to a certain group 
that doesn't allow the source "Example Source", the queryset would return 
articles from the materialized view that omit articles related to the 
source "Example Source".

The challenge I'm facing is that I had a permissions system in place for a 
normalized model, but since switching to materialized view (the 
denormalized model), I'm unsure how to go about implementing something like 
this.

Any help appreciated.

Best,

Will

-- 
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/d0085c29-ad47-4050-91a8-42c14daf81bbo%40googlegroups.com.


Limiting access to data through user permissions?

2020-07-10 Thread Will Meyers


Just need some help getting over a wall I've hit.

I have a web application that whenever a user signs up, is assigned a 
License. This License has CustomPermissions attached to it telling what 
values of a field within a materialized view they have access to. I have an 
API that needs to filter data requested against the User who requested it 
based on the User's license. I drafted some example models below that 
outlines my problem.

class CustomPermission(models.Model):
name = models.CharField(max_length=255)
field = models.CharField(max_length=255)
value = models.CharField(max_length=255)

class License(models.Model):
name = models.CharField(max_length=255)
permissions = models.ManyToManyField(CustomPermissions)
...

class User(AbstractBaseUser):
license = models.ForeignKey(License, on_delete=models.CASCADE)
...

This works fine if I'm only filtering columns with text values. I can just 
do

...
user = request.user
permissions = user.license.permissions.values_list('field', 'value')
return queryset.objects.filter(**{field: value for field, value in permissions})

This issue is that I cannot filter against other datatypes (datetimes for 
example). If I wanted to limit access to data published in the last 90 days 
for example, there's no way to represent that in this model.

To solve this I was thinking of using a sparse table for the 
CustomPermission model. Something like

class CustomPermission(models.Model):
name = models.CharField(max_length=255)
field = models.CharField(max_length=255)
operation = models.CharField(max_length='32')
text_value = models.CharField(max_length=255, null=True, blank=True)
date_value = models.DateField(null=True, blank=True)

Where operation would be equal to '__gt', '__lt', ... things like that. I 
can then just do something similar as before

...
user = request.user
permissions = user.license.permissions.values_list('field', 'operation', 
'text_value', 'date_value')return queryset.objects.filter(**{fld + op: txt_val 
or dat_val for fld, op, txt_val, dat_val in permissions})

But this does not feel right, and can get messy quickly. Any suggestions?

-- 
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/1f8f1c2a-4c21-48a0-ae4d-a128f79a3d0co%40googlegroups.com.


Re: Handling cookies that contain illegal values

2016-02-05 Thread Will Harris
Hey Daniel,

Thanks for the reply. Unfortunately doing this in a custom middleware is 
not an option, as the this processing needs to take place at a very low 
level, at the point where the Request object is being built. By the time 
the request is passed in to the middleware layers for processing, the 
cookies would already have been lost.

Will

On Friday, February 5, 2016 at 12:31:30 AM UTC+1, Daniel Chimeno wrote:
>
> Hello, 
>
>>
>> I have resolved this in my instance as follows in django/http/cookie.py:
>>
>> def parse_cookie(cookie):
>> cookie = re.sub('[^\x20-\x7e]+', 'X', cookie)
>> ...
>>
>>
>>
>> It would be preferable to write that code in a middleware than in the 
> Django code itself.
> Before the middleware that handles the cookie (I guess it would be 
> Session), you can *sanitize* that cookie.
>
> Hope it helps.
>  
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/08dde6a1-1eb8-4428-906b-f619947ea8b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


  1   2   >