Re: Django queries with dates and __lte

2011-09-09 Thread Axel Bock
Indeed :) . I'd never have guessed that. Thanks, 
Axel.


Am 08.09.2011 um 17:47 schrieb Shawn Milochik:

> I think your order by needs to be "-start" instead of "start," then
> take [0] instead of [:1]. That will get the newest entry that matches
> your query.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

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



Django queries with dates and __lte

2011-09-08 Thread Axel Bock
Hello list, 

I have a little trouble setting up a Django query. In my app the user logs time 
spans by entering two time points. I want to make sure that a time span logged 
is not within another span already entered. 
Example: ONE goes from 1000 to 1200, TWO goes from 1400 to 1600. Now I want 
users to be able to log 1300 to 1330, but NOT 1155 to 1300, or 1300 to 1500. 

for that I have a query which should give me the last logged time span (called 
"leg"):
. span_before = 
Leg.objects.filter(start__lte=newly_entered_start_date).order_by('start')[:1]
(all with datetime objects of course)

That works … almost. If I enter the same information twice, I get actually 
ALWAYS the leg before, although using "lte". Example: ONE and TWO are already 
entered. I log TWO again, by accident. Now I expect that my query, which looks 
like … : 
. span_before = 
Leg.objects.filter(start__lte=1400).order_by('start')[:1]
… returns the leg actually starting at 1400 (ltEQUAL, right?), but it does not, 
it returns ONE (the leg starting at 1200). 

Does anyone know why?


Django 1.3, SQLite for now. 


Thanks & greetings, 
Axel.

-- 
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 field display

2011-08-24 Thread Axel Bock
yaah, but that's the most … inconvenient. 

the data model allows for the user to customize the fields he wants to use, 
depending on his requirements. I could start small, but the problem _will_ come 
at some point, so I thought I asked beforehand. 

but thanks for the answer, I already started "small" and postponed the problem. 
we'll see when I get there ;)


greetings, 
axel.



Am 23.08.2011 um 19:22 schrieb Subhranath Chunder:

> Manipulating the form instance attributes at runtime in your view might be 
> possible by modifying some internal fields, but that leads to dirty code and 
> not-so-clean views.
> 
> You can rather use different django forms with different field definitions in 
> your view. This might be the cleanest.
> 
> You can also consider creating some generator function which can return you a 
> django form class on the fly, depending upon the form definition parameters 
> provided to the generator function during runtime. Obviously you need to be 
> careful with this, and consider the cons coming with it.
> 
> 
> On Tue, Aug 23, 2011 at 12:01 AM, Axel Bock <axel.bock.li...@googlemail.com> 
> wrote:
> Hi group,
> 
> I have another question about Django forms. I designed a Form for a Model, 
> but now I want to remove fields depending on some user settings.
> Can I do that?
> 
> Lets assume the following:
> 
> class MyModel(models.Model):
>field1 = TextField(null=True, blank=True)
>field2 = Textfield(null=True, blank=True)
> 
> class MyModelform(forms.Form):
>field1 = TextField()
>fiels2 = TextField()
> 
> def viewform(request):
># some magic here :)
>return render_to_response(context_instance=RequestContext(request, 
> {'form':MyModelForm()}))
> 
> Now I want to disable field2 in the form on display, depending on the user 
> settings. Any suggestions?
> 
> Greetings & thanks,
> Axel.
> 
> --
> 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.
> 
> 
> 
> 
> -- 
> Thanks,
> Subhranath Chunder.
> www.subhranath.com
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

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



Re: CSS question

2011-08-22 Thread Axel Bock
well. inline-block is around since … at least 2007ish, and according to this 
table it _really_ should be no problem for a somewhat new browser. 
and I honestly think IE6&7 support is … not an option, given that ie8 is around 
since 2006!

*if* you have the written requirement … bad. if not, well, I'd go for it. 

of course the table might be wrong. that'd be bad, too :)


greets, 
axel.


Am 22.08.2011 um 21:19 schrieb Cal Leeming [Simplicity Media Ltd]:

> Sorry to be a party pooper, but inline-block is yet again another one of 
> those big no-nos when it comes to cross browser/version.
> 
> http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/
> 
> 
> 
> On Mon, Aug 22, 2011 at 7:35 PM, Axel Bock <axel.bock.li...@googlemail.com> 
> wrote:
> Hah! I can answer something on a Django-list - oh joy :) .
> Yes, indeed I have an idea. *inline-block* may be the css thing for you. 
> 
> A very nice example for that is here: 
> http://www.brunildo.org/test/inline-block.html
> Go to http://www.brunildo.org/ to have an overview over a lot of other stuff, 
> quite helpful.
> 
> 
> Greetings, 
> Axel.
> 
> 
> p.s.: does that mean I'm intelligent? ;)
> 
> 
> Am 21.08.2011 um 23:47 schrieb Joshua Russo:
> 
>> I know this is a bit off topic but I know this place is full of very helpful 
>> intelligent people. :o)
>> 
>> Ok so I have an html block (div, p, doesn't matter what kind), and I fill it 
>> with a label and an input text field. The input is always larger than the 
>> label (rightly so), but the label is always aligned to the top of the block. 
>> I want to center the label in the block but for the life of me, I can't 
>> figure out how.
>> 
>> Any ideas on how to fix it or where to go to get an answer?
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msg/django-users/-/-6G_bvvoyM0J.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

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



Re: CSS question

2011-08-22 Thread Axel Bock
Hah! I can answer something on a Django-list - oh joy :) .
Yes, indeed I have an idea. *inline-block* may be the css thing for you. 

A very nice example for that is here: 
http://www.brunildo.org/test/inline-block.html
Go to http://www.brunildo.org/ to have an overview over a lot of other stuff, 
quite helpful.


Greetings, 
Axel.


p.s.: does that mean I'm intelligent? ;)


Am 21.08.2011 um 23:47 schrieb Joshua Russo:

> I know this is a bit off topic but I know this place is full of very helpful 
> intelligent people. :o)
> 
> Ok so I have an html block (div, p, doesn't matter what kind), and I fill it 
> with a label and an input text field. The input is always larger than the 
> label (rightly so), but the label is always aligned to the top of the block. 
> I want to center the label in the block but for the life of me, I can't 
> figure out how.
> 
> Any ideas on how to fix it or where to go to get an answer?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/django-users/-/-6G_bvvoyM0J.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

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



dynamic field display

2011-08-22 Thread Axel Bock
Hi group, 

I have another question about Django forms. I designed a Form for a Model, but 
now I want to remove fields depending on some user settings. 
Can I do that?

Lets assume the following: 

class MyModel(models.Model):
field1 = TextField(null=True, blank=True)
field2 = Textfield(null=True, blank=True)

class MyModelform(forms.Form):
field1 = TextField()
fiels2 = TextField()

def viewform(request):
# some magic here :)
return render_to_response(context_instance=RequestContext(request, 
{'form':MyModelForm()}))

Now I want to disable field2 in the form on display, depending on the user 
settings. Any suggestions? 

Greetings & thanks, 
Axel.

-- 
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: extending the User profile - which way to go?

2011-08-21 Thread Axel Bock
Thanks for all your replies, it makes sense to wait until it's a performance 
problem :)

Greetings, 
Axel.



Am 21.08.2011 um 22:14 schrieb Simon Connah:

> On 21 Aug 2011, at 19:37, Shawn Milochik wrote:
> 
>> Using a OneToOne field does the same thing as a FK with unique set to true, 
>> and simplifies queryset syntax.
> 
> Good point.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

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



extending the User profile - which way to go?

2011-08-20 Thread Axel Bock
Hi again,

I will need to add some properties to a user in the future. Now I found two 
ways of doing it. First, the Django-way (as described in the Django docs). Then 
I found some other posts from other people, all doing an inheritance of the 
original User-class and using this one. That seems rather elegant, cause there 
is one database lookup less necessary per user lookup. Now I want to go a way 
which is most "Djangonic" - cause I don't want to be stuck somewhere in the 
future with something that breaks on Django 1.4 or whatever.

Any recommendations from the users here? 


Thanks in advance!
Axel.

-- 
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: View-Voodoo: Calling functions in a view does weird things

2011-08-20 Thread Axel Bock

I am _*SO*_ stupid. and equally embarrassed right now. 
oh boy. 
thank you so much.





Am 20.08.2011 um 18:07 schrieb Yaşar Arabacı:

> Do it like this:
> 
> def myview(request):
>if request.method =="POST":
>return call_my_other_func(request)
>else: rtr("index.html")
> 
> def call_my_other_func(request):
># do something with the data
>messages.info(request, "hello world")
>return rtr("index.html", context_instance=RequestContext())
> 
> 2011/8/20 dm03514 
> I think you're 'call_my_other_function' is returning to the 'myview'
> function
> 
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

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



View-Voodoo: Calling functions in a view does weird things

2011-08-20 Thread Axel Bock
Hi all,

I am new to this list (hello btw :), a beginner of Django, and I have
discovered a _very_ strange thing. Basicall I have a view handling a
file upload (see shortened code below). Depending on a select field a
function gets called handling the stuff, and returning. (rtr =
render_to_response). Now. The handler function sets a message.

That does not work.

But. If I copy-and-paste the code of the function
"call_my_other_function" into the if-block in myview, it does.

I don't get it - at all. Can someone please explain?

Thanks in advance & greetings,
Axel.


def myview(request):
if request.method =="POST":
call_my_other_func(request)
else: rtr("index.html")

def call_my_other_func(request):
# do something with the data
messages.info(request, "hello world")
return rtr("index.html", context_instance=RequestContext())

-- 
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: Looking for IDE + FTP

2011-02-13 Thread Axel Bock
"looks"? tried them yourself? :)
for me it looks like aptana tried to focus on ruby/rails, while pycharm
definitely focuses on python/django.

-Axel.


2011/2/13 Cal Leeming [Simplicity Media Ltd] <
cal.leem...@simplicitymedialtd.co.uk>

> Aptana looks nice, PYCharm looks a bit ugly :/
>
> On Sat, Feb 12, 2011 at 5:10 PM, Dylan McCurry wrote:
>
>> I personally use Coda and love it.  Built in ftp, terminal, css
>> editor, and code editor.
>>
>> On Feb 8, 3:30 pm, Karen McNeil  wrote:
>> > I have three Django sites that I've been working on recently and I've
>> > been doing most of the development work in Dreamweaver.  I don't use
>> > any of the wysiwyg features (or, pretty much, any of the Dreamweaver
>> > program features), but I like it because I can do all the the code
>> > edits and the FTP transfers all in one program.  I like being able to
>> > grab a remote file, make some code changes, save and upload all at
>> > once, and view a nice graphical display of the file structure for the
>> > local and remote sites.
>> >
>> > Problem is, Dreamweaver's code view is definitely not built for
>> > Python, and it doesn't look like they have any plans to support it any
>> > time in the foreseeable future.  Which means that I get no color-
>> > coding of the code, and I'm constantly getting indentation errors.
>> >
>> > I've always had Dreamweaver on my computer (a Mac) and so have never
>> > used a separate FTP program, and the only IDE I've ever used is IDLE.
>> > I used IDLE when I was first learning Python, but now that I'm working
>> > with the websites, I find it much more convenient to just open the
>> > files from within DW.  Does anyone know of another, Python-friendly,
>> > program that I could use for both code-editing and ftp?
>> >
>> > Thanks,
>> > Karen
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Looking for IDE + FTP

2011-02-11 Thread Axel Bock
hm, I'm using pycharm right now, and I really think it "kicks ass" ;)
havent looked at the other "usual" ones (komodo, wing, eclipse, etc.) for a
long time, though.

about ftp ... looks like it:
http://www.jetbrains.com/pycharm/webhelp/deployment-connection-tab.html

cheers,
axel.



2011/2/11 jose antunes 

> Try Komodo Edit 5
> It suports ftp/sftp, it's free and supports python
> Great editor just no design view.
>
>
> On Fri, Feb 11, 2011 at 9:55 PM, Jon J  wrote:
>
>> As for a suggestion with an editor, I've been using gedit + extensions
>> for my whole career. It's fast, lightweight, and supports some great
>> syntax highlighting. Auto complete isn't quite as good as DW but it's
>> a tradeoff for linux compatibility and less bloat.
>>
>> On Fri, Feb 11, 2011 at 1:29 PM, Jon J 
>> wrote:
>> > Personally, I haven't really found an editor that satisfies all of my
>> needs.
>> >
>> > However, I can recommend using SSH/SFTP and editing directly on the
>> > remote system. Since I'm assuming you're a django developer, you
>> > should be working primarily in the *NIX world anyway. I've always had
>> > problems with FTP anyway.
>> >
>> > If you do this, it will remove the FTP support requirement.
>> >
>> > On Fri, Feb 11, 2011 at 11:52 AM, Mike Ramirez 
>> wrote:
>> >> On Friday, February 11, 2011 07:16:31 am Osiaq wrote:
>> >>
>> >>> Aptana Studio
>> >>
>> >>>
>> >>
>> >>>
>> >>
>> >> Do you know the future of Aptana now that it's been aquired by
>> >> appacelerator? (I don't know, though granted titanium is not a web
>> building
>> >> tool, which does bode well for the future of aptana outside of
>> titanium.)
>> >>
>> >> Mike
>> >>
>> >> --
>> >>
>> >> Have no friends not equal to yourself.
>> >>
>> >> -- Confucius
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> Groups
>> >> "Django users" group.
>> >> To post to this group, send email to django-users@googlegroups.com.
>> >> To unsubscribe from this group, send email to
>> >> django-users+unsubscr...@googlegroups.com.
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/django-users?hl=en.
>> >>
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Filtering Queryset by Foreign Key Properties

2011-02-11 Thread Axel Bock
Hi,

try this, I guess this should workd (being new here myself :):
OrderPositions.objects.filter(order__type = "A")


and maybe have a look here:
http://docs.djangoproject.com/en/1.2/ref/models/querysets/#field-lookups


Cheers,
Axel.


2011/2/11 josch 

> Hi,
>
> I`m searching for a solution for the following problem:
>
> I have, for example, those two classes:
>
> class Order(self):
>type = models.CharField(1)
>
> class OrderPositions(self):
>order = ForeignKey(Order)
>
>
> Now I want to get every Order Position, whoose order has the type, for
> example 'A'.
>
> queryset = OrderPositions.objects.filter(order.type='A')
>
> Of course this does not work, I just wanted to make clear what I want
> to to.
>
> What is the best way to handle a demand like this.
>
> 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.
>
>

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



DateTime entry like in the admin interface

2011-02-11 Thread Axel Bock
Hi again,

I have in my model a DateTime input, which the admin interface automatically
displays as two separate DATE and TIME input fields. I would like to do
that, too.

Can anyone tell me how? :)


Thanks & greetings,
Axel.

-- 
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: model form validation

2011-02-05 Thread Axel Bock
Shawn,

thanks for hint, I'll give that a try. Also I have some questions, for my
own clarification of things:

1) using your method - would is_valid() retur true then?
2) in my form display I should hide the "takeoff" field then, correct?
3) I alredy tried to override clean_takeoff() - it didn't get called. Any
ideas, why?


Axel.



2011/2/5 Shawn Milochik <sh...@milochik.com>

> On 02/05/2011 01:08 PM, Axel Bock wrote:
>
>> practically:
>> - the user enters "0300" in the datetime field.
>> - I make "0300" into date=0, time=03:00, valid field.
>>
>
> Axel,
>
> In your example, you're wanting to populate a DateTime field in a model,
> but you want to allow the user to enter a string which would be invalid for
> the field.
>
> One way to do this is to add an additional field to your form.
>
> Example, given your 'takeoff' field:
>
>1. Add a charfield named takeoff_str in your form definition.
>
>2. Add a method named clean_takeoff_str to your form definition.
>
>In this function, check to ensure that the string entered is a valid
>HHMM value, if not raise a forms.ValidationError.
>
>Then, create a valid datetime from the input, and set
>self.cleaned_data['takeoff'] equal to this value.
>
>
> Shawn
>
> --
> 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<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: model form validation

2011-02-05 Thread Axel Bock
let's make an example: in the datetime fields of the forms there will only
be a time, which is ok for the user. the date will be added later by some
background logic, for convenience.

practically:
- the user enters "0300" in the datetime field.
- I make "0300" into date=0, time=03:00, valid field.

if you have any other idea how to do this - don't hesitate :) . and maybe
(hopefully) this will also solve the mysteriously vanished datetime values.


Thanks!
Axel.



2011/2/5 Shawn Milochik 

> What exactly are you trying to accomplish? I'm not sure overriding is_valid
> is a good idea; it's not a part of the validation -- it's how a model knows
> that the validation was successful.
>
> In your sample view, you're calling is_valid on the formset, not the forms
> in the formset. That would explain why your 'is_valid' is never called.
>
> You can iterate through the formset to get at the actual form instances
> inside.
>
> Shawn
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



model form validation

2011-02-05 Thread Axel Bock
hi all,

really, I don't get this model form validation stuff. And currently, right
now, I am immensely p*** off, because either the documentation is horribly
bad (at least for me) or I am simply way too stupid.

okay, enough rant, let's get practical - on to my little problem. I want to
do model formset validation.

I have a modelform like the one below. And I wanted to intercept the
is_valid() method of the modelform, to prepare some stuff before the
standard validation kicks in. But, the fun fact is, is_valid NEVER gets
called - at least my breakpoints in that method are not hit. The clean()
method does get called, but this one is totally useless to me ... here the
validation seems to be done already. I also have the funny little thing that
the TimeInput fields are not in the cleaned_data dict, but that's another
thing maybe.

Can anyone help me out here, please? That can't be that hard ...

Thanks in advance & greetings,
Axel.


class LegForm(forms.ModelForm):
class Meta:
model = Leg
widgets = { 'flownmission'  : widgets.HiddenInput(),
'blockoff'  : widgets.TimeInput( attrs={ 'size':10 }
),
'takeoff'   : widgets.TimeInput( attrs={ 'size':10 }
),
'landing'   : widgets.TimeInput( attrs={ 'size':10 }
),
'blockon'   : widgets.TimeInput( attrs={ 'size':10 }
),
'num_landings'  : widgets.TextInput( attrs={ 'size': 5 }
),
  }

def is_valid(self):
return True # never EVER gets called

def clean(self):
super(forms.ModelForm, self).clean()
return self.cleaned_data


@login_required
def addlegs(request, mission_id=None):
LegFormSet = modelformset_factory(Leg, form=LegForm, extra=3)
if not request.method == "POST":
# if mission_id is set we're being called from another method in
here ... :)
formset = LegFormSet(queryset=Leg.objects.none())
return rtr(request, 'flightlog/templates/addlegs.html',
{"formset":formset})
else:
formset = LegFormSet(request.POST)
formset.is_valid()
return redirect("/")

-- 
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 following tutorial part 1

2011-01-29 Thread Axel Bock
you should not. are you IN c:\...\scripts when you type in
"django-admin.py"? AFAIK windows adds the current directory always to the
path.

and it's AXEL ;)



2011/1/29 Panupat <panup...@gmail.com>

> Hi Alex. Thank you for you suggestion.
>
> It seems I can get the script to run if I type out the full path.
>
> C:\Python27\Scripts\django-admin.py startprofect mysite
>
> C:\Python27 is already added to my windows' PATH. Proably will need to
> add C:\Python27\Scripts to it too.
>
>
> On Jan 30, 1:44 am, Axel Bock <mr.axel.b...@gmail.com> wrote:
> > hm ... my windows times are over quite a while, BUT ...
> >
> > 1) try associating the .py extension with the python commandline
> > interpreter.
> > 2) syntax error? send a screendump maybe, or your exact command line ...
> it
> > _should_ work without problems.
> >
> > can you execute other simple python scripts?
> >
> > cheers,
> > axel.
> >
> > 2011/1/29 Panupat <panup...@gmail.com>
> >
> > > I'm kinda stuck and would greatly appreciate any help.
> >
> > > I followed these turorials and got Django to install. Was able to
> > > import Django and print out the version correctly. I'm running
> > > Apache2.2 on windows 7 with mod_wsgi
> >
> > >http://docs.djangoproject.com/en/1.2/intro/install/
> >
> > > But moving forward to part 1, It says, cd to the directory and run the
> > > command
> > > django-admin.py startproject mysite
> >
> > > This is where I don't understand.
> > > - running the command from cmd, it says django-admin.py is not
> > > recognized as command.
> > > - if I run python first, it says syntax error.
> >
> > > Am I missing something from the tutorial? Does the project need to be
> > > in a particular folder in order for the .py file to be executable? Is
> > > there anything else I need to add to windows other than adding C:
> > > \Python27 to 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
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: need help following tutorial part 1

2011-01-29 Thread Axel Bock
hm ... my windows times are over quite a while, BUT ...

1) try associating the .py extension with the python commandline
interpreter.
2) syntax error? send a screendump maybe, or your exact command line ... it
_should_ work without problems.

can you execute other simple python scripts?


cheers,
axel.




2011/1/29 Panupat 

> I'm kinda stuck and would greatly appreciate any help.
>
> I followed these turorials and got Django to install. Was able to
> import Django and print out the version correctly. I'm running
> Apache2.2 on windows 7 with mod_wsgi
>
> http://docs.djangoproject.com/en/1.2/intro/install/
>
> But moving forward to part 1, It says, cd to the directory and run the
> command
> django-admin.py startproject mysite
>
> This is where I don't understand.
> - running the command from cmd, it says django-admin.py is not
> recognized as command.
> - if I run python first, it says syntax error.
>
> Am I missing something from the tutorial? Does the project need to be
> in a particular folder in order for the .py file to be executable? Is
> there anything else I need to add to windows other than adding C:
> \Python27 to 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
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: modelformset not iterable

2011-01-24 Thread Axel Bock
forget it. it was formset.forms ...
I *SWEAR* there is another example just with "for form in formset" ...

thanks anyway :)
Axel.



2011/1/25 Axel Bock <mr.axel.b...@gmail.com>

> Hello all,
>
> I am trying to implement something quite simple, in my eyes. But it does
> not work at all ... . Basically, I create a modelformset_factory with a
> model of mine, and pass the instantiated modelformset to my template to
> render. And I get the message *Caught TypeError while rendering: '
> LegFormFormSet' object is not iterable ...* (note the *FormForm*-part in
> the error message? it should be one "*Form*" only ... shouldn't it?)
>
> The code looks like this:
> def addlegs(request, mission_id=None):
> *LegFormSet* = modelformset_factory(Leg, extra=3)
> if not request.method == "POST":
> # if mission_id is set we're being called from another method in
> here ... :)
> *formset = LegFormSet(queryset=Leg.objects.none())*
> return rtr(request, 'flightlog/templates/addlegs.html', {*
> "formset":formset*})
> else:
> return redirect("/")
>
> and the template like this:
> {% load widget_tweaks %}
> 
> {% csrf_token %}
> {{ formset.management_form }}
> 
> {% for form in formset %}
> {% for field in form %}
> {{ field|add_class:"myclass" }}
> {% endfor %}
> {% endfor %}
> 
> 
> 
>
> in my eyes that's all pretty simple, but it drives me crazy right now cause
> it does not work at all. in case you wonder: the management_form is rendered
> correctly. The rendered code for this looks like this:
>  id="id_form-TOTAL_FORMS"/>   name="form-INITIAL_FORMS"
>   value="0"
>   id="id_form-INITIAL_FORMS"/>
> 
>
>
> any ideas, anyone?
>
>
> Thanks for any help & greetings,
> Axel.
>

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



modelformset not iterable

2011-01-24 Thread Axel Bock
Hello all,

I am trying to implement something quite simple, in my eyes. But it does not
work at all ... . Basically, I create a modelformset_factory with a model of
mine, and pass the instantiated modelformset to my template to render. And I
get the message *Caught TypeError while rendering: 'LegFormFormSet' object
is not iterable ...* (note the *FormForm*-part in the error message? it
should be one "*Form*" only ... shouldn't it?)

The code looks like this:
def addlegs(request, mission_id=None):
*LegFormSet* = modelformset_factory(Leg, extra=3)
if not request.method == "POST":
# if mission_id is set we're being called from another method in
here ... :)
*formset = LegFormSet(queryset=Leg.objects.none())*
return rtr(request, 'flightlog/templates/addlegs.html', {*
"formset":formset*})
else:
return redirect("/")

and the template like this:
{% load widget_tweaks %}

{% csrf_token %}
{{ formset.management_form }}

{% for form in formset %}
{% for field in form %}
{{ field|add_class:"myclass" }}
{% endfor %}
{% endfor %}




in my eyes that's all pretty simple, but it drives me crazy right now cause
it does not work at all. in case you wonder: the management_form is rendered
correctly. The rendered code for this looks like this:




any ideas, anyone?


Thanks for any help & greetings,
Axel.

-- 
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: ModelForm validation

2010-12-30 Thread Axel Bock
Ah :) . I should have thought of that ... pretty stupid of me :)

Thanks for the clarification, I'll try that, makes perfect sense!


/Axel.



2010/12/30 derek <gamesb...@gmail.com>

> Alex
>
> And I seem to have been equally unclear :}
>
> I agree that cleaned_data is only available after is_valid() - the
> point being that your form *will* be valid if you have set the value
> for that field in a hidden input.  I do not see that this can be a
> "security risk" - the default that you are setting beforehand is a
> dummy (meaningless) value which, in any case, you are going to be
> overriding.  How is this done?  Consider this example from the Django
> Book (http://www.djangobook.com/en/1.0/chapter07/):
>
> def contact(request):
>if request.method == 'POST':
>form = ContactForm(request.POST)
>if form.is_valid():
>topic = form.clean_data['topic']
>
> Now if you wanted to overide the topic, you could instead have:
>topic = 'my custom text'
>
>
> Hope this is clearer!
>
> Derek
>
> On Dec 29, 4:07 pm, Axel Bock <mr.axel.b...@gmail.com> wrote:
> > hi derek,
> >
> > thanks for your hints - was I really that unclear? hm.
> >
> > anyway, could you please give an example about how to "override/check the
> > value for that field after the form POST"? I don't seem to be able to do
> > that, and believe me, I have read the docs.
> >
> > I think cleaned_data is only available after is_valid() was called, but
> > is_valid() throws an exception because the required field is missing -
> and I
> > can't set it.
> >
> > The hidden field thing is the last thing I wanted to try. bad style, you
> > know :) , cause security risk.
> >
> > thanks!
> > Axel.
> >
> > 2010/12/29 derek <gamesb...@gmail.com>
> >
> >
> >
> >
> >
> >
> >
> > > Axel
> >
> > > Not sure I have followed all your requirements, but perhaps you can
> > > try:
> > > * set a default value for the required field
> > > * mask the required field on the form being shown to the user (make it
> > > hidden)
> > > * override/check the value for that field after the form POST and data
> > > "clean" (see:
> > >http://docs.djangoproject.com/en/dev/topics/forms/?from=olddocs#proce.
> ..
> > > )
> >
> > > HTH
> > > Derek
> >
> > > On Dec 28, 10:21 pm, Axel Bock <justsomeoneoutth...@gmail.com> wrote:
> > > > Hi all,
> >
> > > > I have this little problem. In my little webapp I have a data model
> which
> > > > defines several required fields. Depending on WHO is logged on, some
> of
> > > > these fields should not be changed by the user and be pre-filled (or
> > > better:
> > > > post-filled) by the application.
> >
> > > > Currently I delete the fields out of the formset like this:
> > > > # prevent entering missions for all other bases
> > > > del missionform.fields['base']
> >
> > > > so the field gets not rendered in the view. Which works nicely.
> >
> > > > Unfortunately base is required, so the validation fails. Now how can
> I
> > > > insert the missing values into the POST data? I tried this:
> > > > if request.user.userflag.is_student:
> > > > logging.error("studen")
> > > > inst=FlownMission(
> > > > student=request.user,
> > > > base=request.user.studentinfo.current_base
> > > > )
> > > > flownmission = FlownMissionForm(request.POST, instance=inst)
> >
> > > > which does not work at all :( . The validation fails all the time ...
> . I
> > > > just need to inject 2 required values somewhere in the POST data, but
> I
> > > have
> > > > no clue how.
> >
> > > > Any help would be greatly appreciated, and I am a total django "newb"
> ...
> > > :)
> >
> > > > Thanks & greetings,
> > > > Axel.
> >
> > > --
> > > 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<django-users%2bunsubscr...@googlegroups.com>

Re: ModelForm validation

2010-12-29 Thread Axel Bock
hi derek,

thanks for your hints - was I really that unclear? hm.

anyway, could you please give an example about how to "override/check the
value for that field after the form POST"? I don't seem to be able to do
that, and believe me, I have read the docs.

I think cleaned_data is only available after is_valid() was called, but
is_valid() throws an exception because the required field is missing - and I
can't set it.

The hidden field thing is the last thing I wanted to try. bad style, you
know :) , cause security risk.


thanks!
Axel.



2010/12/29 derek <gamesb...@gmail.com>

> Axel
>
> Not sure I have followed all your requirements, but perhaps you can
> try:
> * set a default value for the required field
> * mask the required field on the form being shown to the user (make it
> hidden)
> * override/check the value for that field after the form POST and data
> "clean" (see:
> http://docs.djangoproject.com/en/dev/topics/forms/?from=olddocs#processing-the-data-from-a-form
> )
>
> HTH
> Derek
>
> On Dec 28, 10:21 pm, Axel Bock <justsomeoneoutth...@gmail.com> wrote:
> > Hi all,
> >
> > I have this little problem. In my little webapp I have a data model which
> > defines several required fields. Depending on WHO is logged on, some of
> > these fields should not be changed by the user and be pre-filled (or
> better:
> > post-filled) by the application.
> >
> > Currently I delete the fields out of the formset like this:
> > # prevent entering missions for all other bases
> > del missionform.fields['base']
> >
> > so the field gets not rendered in the view. Which works nicely.
> >
> > Unfortunately base is required, so the validation fails. Now how can I
> > insert the missing values into the POST data? I tried this:
> > if request.user.userflag.is_student:
> > logging.error("studen")
> > inst=FlownMission(
> > student=request.user,
> > base=request.user.studentinfo.current_base
> > )
> > flownmission = FlownMissionForm(request.POST, instance=inst)
> >
> > which does not work at all :( . The validation fails all the time ... . I
> > just need to inject 2 required values somewhere in the POST data, but I
> have
> > no clue how.
> >
> > Any help would be greatly appreciated, and I am a total django "newb" ...
> :)
> >
> > Thanks & greetings,
> > Axel.
>
> --
> 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<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



ModelForm validation

2010-12-28 Thread Axel Bock
Hi all,

I have this little problem. In my little webapp I have a data model which
defines several required fields. Depending on WHO is logged on, some of
these fields should not be changed by the user and be pre-filled (or better:
post-filled) by the application.

Currently I delete the fields out of the formset like this:
# prevent entering missions for all other bases
del missionform.fields['base']

so the field gets not rendered in the view. Which works nicely.

Unfortunately base is required, so the validation fails. Now how can I
insert the missing values into the POST data? I tried this:
if request.user.userflag.is_student:
logging.error("studen")
inst=FlownMission(
student=request.user,
base=request.user.studentinfo.current_base
)
flownmission = FlownMissionForm(request.POST, instance=inst)

which does not work at all :( . The validation fails all the time ... . I
just need to inject 2 required values somewhere in the POST data, but I have
no clue how.


Any help would be greatly appreciated, and I am a total django "newb" ... :)


Thanks & greetings,
Axel.

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



Formsets, forms and related editing

2010-09-28 Thread Axel Bock
Hello again,

after some trying and not coming to a successful end I might need a hint or
two with the following construction.

Assume a pilots flight log: Each flight can have several legs, and a
purpose. So basically the model looks like this:

Mission:
Pilot
Purpose
...

Leg:
Mission: ForeignKey('mission')
Departure
Target
Time

The relationship is Mission (1) --> (*) Leg (one to many). The legs are
REQUIRED for the Mission to be complete.

Now I am trying to design a view which presents an input for the Mission AND
the leg part, so when submitting you create a Mission including its legs.
There are also several restrictions, one of them being that a pilot can only
log his own Missions. For this reason I do not present a "Pilot" entry
field, and intend to fill in the Pilot later (it's of course a registered
user, so I am following the procedure described in the Django docs -
save(commit=False), update the field value).

But this does not work. :/

The view is roughly this code:
mission = MissionForm()  # a modelform
LegFormSet = inlineformset_factory(Mission, Leg, form=LegForm, extra=1,
can_delete=False)
legforms = LegFormSet(prefix="legformset")
render_to_response("...", { ... }, context_instance=...)

The View seems to work all right, but the processing does not. The
processing code is roughly:
mission = MissionForm(request.POST).save(commit=False)
# it seems to abort here with the error "The Mission could not be
created because the data didn't validate"
legs =[f.save(commit=False) for f in LegFormSet(request.POST,
prefix="legformset")]

Are there any best practices when doing such kind of thing? Am I doing it
wrong?


thanks in advance for any help & greetings,
Axel.

-- 
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: JavaScript with Dango

2010-09-26 Thread Axel Bock
I gotta say this is the kind of answer which usually upsets me for obvious
reasons, although I gotta admit the question surely is not very well
phrased, too :)

But well. I just discovered dajaxproject.com from another thread - maybe you
could start from there. It seems to be a framework which coupoles Django
with some Ajax libs to some extend, if that's what you want. I only had a
short look and filed it for later.

http://www.dajaxproject.com/


HTH,
Axel.



2010/9/26 CrabbyPete 

> Yes.
>
> On Sep 26, 7:48 am, aug dawg  wrote:
> > Does Django work with JavaScript? If so, how can I use JavaScript in my
> > Django projects?
>
> --
> 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.
>
>

-- 
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: Python unexpectedly quit

2010-09-24 Thread Axel Bock
maybe I was a little bit out of sleep today :) . tried to get auth.User
subclassing working til 4am in the morning ... and what do you mean with
"not picky enough"?



2010/9/24 Steve Holden <holden...@gmail.com>

> On 9/24/2010 2:23 PM, Axel Bock wrote:
> > Anything wrong here? I must say, the framework for the people "with
> > deadlines" is giving me a *really* hard time so far :) .
>
> Maybe you aren't in enough of a hurry? And, by the way, it's
> *perfectionists* with deadlines. Maybe you aren't being picky enough?
>
> regards
>  Steve
> --
> DjangoCon US 2010 September 7-9 http://djangocon.us/
>
> --
> 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<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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

2010-09-24 Thread Axel Bock
oh f...

thanks.

2010/9/24 Scott Gould 

>
> > def logout(request):
> > logout(request)
>
> Infinite loop, no?
>
> --
> 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.
>
>

-- 
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: subclassing UserCreationForm

2010-09-24 Thread Axel Bock
2010/9/24 Jason 

>
> "Creating the relationship between User and UserInfo has some
> implications I'd like to avoid on a model-level"
>
> Specifically what are you referring to here? Because anytime you
> subclass in Django you are basically doing the exact thing in the
> database behind the scenes and as result accessing the data turns out
> to be pretty similar (just about as easy both ways).
>

Well, first I can to "if X == Student: ...", and I know the fields will be
there.
Second, User will have no additional properties (as I understand), but once
I do "Model --> User" relations ALL users will have that property. So each
user might have the .course property, AND the .subject property (which might
be for teachers), AND the .function property, which might be for
administrative staff (I'm making things up here :). So all properties would
be present, they may not be mandatory, cause a teacher is never part of a
course, so I have to ensure data consistency in the application logic. That
sucks.

Subclassing relieves me from this just nicely, AND this is the mother of all
prototype examples of OOP - base class, specialized subclasses. The only
thing more cliché would be "Car" -> "Van" / "Compact" / ... .

I might have a look into groups, but I need certain properties for the
users. Groups seem to manage the database permissions just fine, but I'm all
in for class / instance properties.

The best part is: In theory it is all VERY simple: The subclassing works
just fine. It even seems to run a feature of Django - subclassing of models,
since version IForgotWhich. Also the model behaves just as expected, the
database looks like it should. But then I run into trouble because I cannot
display ONE --CENSORED-- FIELD as of now in the admin "create" interface.
And so far no one was able to give me an answer, although I found examples
on the web - unfortunately they don't work here. And everything I try simply
does not work with the magic of that --censored-- UserAdmin manager. (Yes, I
am a bit frustrated here).

Right now I switch between two different Admin classes to create some test
users, which SUCKS.

I surely *cannot* be the only guy who does things like this, or who came up
with that idea. Can I? I mean, I posted the articles of other people,
who did just the same, right??

Although I still like Django, cause I really just started with it. But ...
well, my patience is getting a tiny little bit thin, if I don't get some
little successes out of it soon.



So --- am I right? Specifically about the "All users have that property
then" part?

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



Python unexpectedly quit

2010-09-24 Thread Axel Bock
HI all,


another problem here: On my system (MacBook Pro, OS X newest version) Python
"unexpectedly" quits when I invoke localhost:8000/logout.
The code for that looks like this:


#urls.py:

urlpatterns += patterns('webflog.flightlog',
# 
(r'^logout/',   'views.logout'),
)


# views.py

def logout(request):
logout(request)
return HttpResponseRedirect('/login')


Anything wrong here? I must say, the framework for the people "with
deadlines" is giving me a *really* hard time so far :) .


Thanks in advance!
Axel.

-- 
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: subclassing UserCreationForm

2010-09-24 Thread Axel Bock
Thanks a lot for your answers.

I thought subclassing users is a nice idea, cause a Student IS a user, with
a few extended attributes. I decided to subclass users, because ...

* when adding a UserInfo -> user relationship (class UserInfo(Model): user =
ForeignKey('User')), ALL users having a userinfo. this is bad if I have
different kind of users (I do.), so I do not really want that.

* A user can be created without attaching the UserInfo information (I did
this already, and unless I did something wrong, I could do just that). So I
have to add application logic to make sure that a Student actually has a
UserInfo object attached. Also because of my different system users it would
make no sense to actually attach that to EVERY user

* I have read this one:
http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/.
Subclassing models actually seems to be the "new" way of doing things, so
why should be User an exception to this rule?

* I also have read this article:
http://blog.picante.co.nz/post/Subclassing-User-to-add-extra-fields-in-the-Django-Admin-Site/

* And this article:
http://www.kolios.dk/2010/01/22/how-to-extend-django-user-class-and-change-authentication-middleware/(actually
the main one why I wanted this)

So, all in all, if it is possible AND a common way to go, I'd prefer it that
way. Creating the relationship between User and UserInfo has some
implications I'd like to avoid on a model-level.

If they are all wrong, I REALLY think the API should not let people do this.
If they are right, then I still lack an anwer for my problem - the single
f*cked up field in the create student form, which I'd like to shoot on sight
once it's there and then burn the ashes :) . (I have had not much sleep
tonight ...)


Thanks!
Axel.

2010/9/24 Vasil Vangelovski 

>
> Mainly, I just don't think you're subclassing User for the right
>> reasons. In fact, I can't really think of anytime I would subclass
>> it.  Usually adding a related table is a better way to go (lookup
>> django user profiles for example).
>>
>
>  There are times when the builtin User model is not enough, that's why
> there is a way to specify user profiles. There are times when you want to be
> sure that every user in the system has a profile (some filed in the profile
> is required for the system to work properly), even for the users added from
> the admin. This can lead people to try all kinds of hacks, like subclassing
> user, which there is a way to implement but will lead you in all kinds of
> trouble. Then there is the case where you want all users to be staff no
> matter what, which makes the field superficial, but leads to extra
> uneccessary work on the developers part to make sure it works that way.
> These are all real world scenarios I've encountered, and I'm guilty of
> pushing a subclassed user model in the past.
>
> If the api leads a lot of people to try all kinds of hacks around it to
> achieve what they want, blame the API not the people. Providing concrete
> models for users in contrib leads to more pain than the time or trouble it
> saves.
>
> --
> 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.
>

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



subclassing UserCreationForm

2010-09-23 Thread Axel Bock
Hello all,

I must admit - I am going crazy. With something I thought should be
incredibly simple, but maybe I am just too f**king stupid.

All right, here comes my problem. I have subclassed "User" as "Student" and
added some required fields, one of them being "Course":

# models.py
class Student(User):
course = models.ForeignKey('Course')

So far, so good. Now I couldn't create a Student with an initial password -
the password field was plaintext, and the "change password" form wouldn't
work. I dug through the code and some postings, and discovered that if I
used a custom admin class it would just work fine, with the advantage that I
could exclude some fields I don't need in the admin view of the Students.
That basically looks like this:

# admin.py
class StudentAdmin(UserAdmin):
fieldsets = ( #...
)
admin.site.register(Student, StudentAdmin)
*
Then* I got another annoyance. If I tried to create a Student now, I was
confronted with the "usual" User creation screen. (Huh? ... ok, dig a bit in
Django internals, one can only learn ...). Basically I wouldnt mind, but the
Student creation does not work any more - the simple add user screen will of
course set no "course" value in the Student model, So I dug further. I
discovered that the user creation was handled by a form called
UserCreationForm, and this form explicitly excluded alot of stuff.

But now the magic went crazy. If I look at the UserCreationForm class, I
see:

class Meta:
model = User
fields = ("username",)

WTF? The only field which *should* be seen is "username", according to the
docs (according to
http://docs.djangoproject.com/en/1.2/topics/forms/modelforms/). But there is
password AND username. Aha. I am pretty confused now. But not without
optimism. I tried subclassing the form now, which looked something like
this:

*class StudentCreationForm(UserCreationForm):
class Meta():
model = Student
fields = ('course')
*
class StudentAdmin(UserAdmin):
#fields = ('first_name', 'family_name', 'password', 'course', 'base')
fieldsets = ( # ... cut out
*add_form = StudentCreationForm*

And the result? No luck. WhatEVER I do (replacing UserCreationForm with
subclass of ModelForm, overriding get_form(), and some other things), the
form will only and inevitably show "username" and "password".

And it's about two hours now.

Help.

Please.


Thanks!
Axel.

-- 
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: Relationship question: What do I do wrong?

2010-09-18 Thread Axel Bock
wow, thanks a alot guys for those efforts. indeed, that explanation is
better than the original docs :) .
I get it now, I changed it, and I guess the data model (v1.0 ...) is
sufficient for the first test run.

it's nice btw to get such a good support here in the forums! this is not
granted at all.


thanks & greetings!
Axel.

2010/9/18 Steve Holden 

> On 9/18/2010 3:23 PM, werefr0g wrote:
> >  Hello,
> >
> > I was quite laconic previously in order to spare you my "english". Sorry
> > if you found this rude.
> >
> > Well, you describe the relashionship from one model perspective (Meal)
> > while setting your field (side1).By setting Field side1 in Meal as
> > models.ForeignKey, you state that a Meal has a relationship to one Side
> > as side1 but you also explicitly state that one Side can be related to
> > many Meal through this relashionship.
> >
> > If my_meal is your Meal instance, you'll use my_meal.side1 to reach
> > related Side through side1 relashionship. With my_side as a Side
> > instance, you'll use my_side.meal_set to reach all Meal related to
> > my_side regarding the same relashionship.
> >
> > Now, taking side2 Field in account, you can use my_meal.side2 but you
> > can no longer use my_side.meal_set: you cannot distinguish which
> > relashionship is implied this way. The related_name parameters allows
> > you to make that distinction. Here you can place 'with main course' and
> > 'post main course' and, by the way, I think you should name fields
> > with_main_course_side and post_main_course_side or alike.
> >
> > You'll find at
> >
> http://docs.djangoproject.com/en/dev/topics/db/queries/#backwards-related-objects
> > more details with an explanation of the nature of side1.meal_set object
> > type's nature _ in better english ;)
> >
> That's a very clear explanation, and much more concise than the
> documentation. Congratulations. I also like your naming recommendation.
>
> Of course, if you wanted the flexibility of an indefinite number of
> sides you would usually use a many-to-many relationship between Meals
> and Sides, perhaps with using a "through" table (? is that what they are
> called) to add one or more status columns to store further attributes of
> the relationship such as "post_main_course" / "with_main_course" (useful
> for searching).
>
> regards
>  Steve
> --
> DjangoCon US 2010 September 7-9 http://djangocon.us/
>
> --
> 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.
>
>

-- 
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: Relationship question: What do I do wrong?

2010-09-18 Thread Axel Bock
thanks for all the explanations! i had a look into the database tables - and
they do just what i expected. so I just leave it at changing the referal
property names ...

thanks & greetings,
Axel.

2010/9/18 bruno desthuilliers <bruno.desthuilli...@gmail.com>

> On 18 sep, 16:23, Axel Bock <mr.axel.b...@gmail.com> wrote:
> > 2010/9/18 bruno desthuilliers <bruno.desthuilli...@gmail.com>
> > > Django automatically build the "reverse" relationship from SideLists
> > > (which should be renamed "Side" IMHO) to Meal, using the default
> >
> > can I prevent this?
>
> Prevent what ? The orm building the reverse relationship ? No, unless
> you hack django. But why would you prevent this ?
>
> > I read up on this - again - and it seems I then have the
> > following construct:
> >
> > meal.side1.meal_set() == meal # correct?
>
> Nope. meal.side1 yields the Side object related to meal thru this
> ForeignKey, then side1.meal_set.all() yields a queryset of _all_ Meal
> objects related to this Side object thru this ForeignKey. All you can
> assert here is that meal is in meal.side1.meal_set.all()
>
> > all that the sides are is a
> > "over-complex" choice box. I actually would like to use a simple choice
> box,
> > _but_ the sides can change and so I just want to add a database row, and
> not
> > change code.
>
> Yeps, using a foreign key is the right way to model this in a
> relational database. You may not care about the reverse relationship
> in this application, but this relationship exists and is often used
> one way or another in most apps.
>
> --
> 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<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Relationship question: What do I do wrong?

2010-09-18 Thread Axel Bock
2010/9/18 bruno desthuilliers <bruno.desthuilli...@gmail.com>

>
> On 18 sep, 08:26, Axel Bock <mr.axel.b...@gmail.com> wrote:
> > Now I get an error when compiling this.
>
> s/compiling/importing/
>

yah, all right :) .



> > Any help here? I'm quite new to dango, so a little hint would be
> > nice :)
>
> Django automatically build the "reverse" relationship from SideLists
> (which should be renamed "Side" IMHO) to Meal, using the default
>

can I prevent this? I read up on this - again - and it seems I then have the
following construct:

meal.side1.meal_set() == meal # correct?

That really makes no sense in that area. all that the sides are is a
"over-complex" choice box. I actually would like to use a simple choice box,
_but_ the sides can change and so I just want to add a database row, and not
change code.



> To make a long story short, you need to explicitely specifies the
> related accessor name using the "related_name" argument in the
> ForeignKey constructor as werefr0g suggested.
>

tried that, and it seems to work :)


thanks a lot!
Axel.

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



Relationship question: What do I do wrong?

2010-09-18 Thread Axel Bock
Hello,

I am currently experimenting with a little webapp, and I have the
following problem. I want to assign two properties of the same type to
a class. (Stupid) Example: I have a meal, and it comes with two sides.
The sides itself are another database key - they can change on a
whim :) . It looks something like this:

class Meal(models.Model):
side1 = models.ForeignKey('SidesList')
side2 = models.ForeignKey('SidesList')
# 

class SidesList(models.Model):
name = models.CharField(max_length=20)
availability = models.BooleanField()

Now I get an error when compiling this. See, I need exactly two
properties of the same type (side1, side2) in two _different_ object
properties. The meal comes with exactly two sides, you see? :) And
they must be distinguishable (something like post-main-course side",
and "side with main course" out of the same pool).

The error is: "Accessor for field 'side1' clashes with related field
'SidesList.leg_set'." (the same error for side2).

Any help here? I'm quite new to dango, so a little hint would be
nice :)


thanks a lot in advance,
Axel.

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