Re: Is this not allowed select_related()

2007-08-09 Thread Doug B
maybe something like this... class Employee(models.Model): # your employee model fields here, no FKs to Contact or Assignment models ... class EmployeeAssignment(models.Model): active = models.BooleanField() # I added this employee = models.ForeignKey(Employee) ... class

Re: Templates: dynamic attribute referencing?

2007-08-08 Thread Doug B
See if this tag won't work for you: class ObjectAttribNode(template.Node): def __init__(self, obj, attr): self.obj = obj self.attr = attr def render(self, context): print self.attr try: obj = resolve_variable(self.obj, context)

Re: Dynamic values for BaseForm

2007-08-07 Thread Doug B
form = NewsForm(request.POST, somegroup=somegroup) given your form __init__ definition, you are passing POST into the spot for somegroup. What I did to get around this was something like this: class NewsBaseForm(BaseForm): def __init__(self, *args, **kwargs): nkwargs =

Re: How to split up views into different files...

2007-08-06 Thread Doug B
You can make a 'views' subfolder in your app folder, and make sure it contains an __init__.py file (can be empty). My personal opinion is that going overboard trying to make your python file structure 'neater' will eventually bite you in the ass. It wasn't too bad for views, but became import

Re: Textile causing UnicodeDecodeError

2007-08-05 Thread Lucky B
from here: http://64.233.169.104/search?q=cache:bswtnEOJ33QJ:douglasjarquin.com/blog/2007/07/13/unicode-django-and-textile/+textile+unicode=en=clnk=3=us=firefox-a try textile.textile(str(self.source)) On Aug 5, 12:34 pm, Martin Gilday <[EMAIL PROTECTED]> wrote: > I have added textile.py to my

Re: '_QuerySet' problem

2007-08-05 Thread Doug B
A queryset is kind of like a list, you can slice it, access by index, or iterate through it. I'm not quite sure what you are trying to do, but to access the individual user objects you have to fetch them from the queryset somehow: users = User.objects.all() by index: print users[0].user print

Re: age in years calculation

2007-08-03 Thread Lucky B
how about surrounding the statement with a try and work the leap year to regular year case with the exception? On Aug 3, 10:16 am, Bram - Smartelectronix <[EMAIL PROTECTED]> wrote: > Jonathan Buchanan wrote: > > > > > >http://toys.jacobian.org/presentations/2007/oscon/tutorial/ > > > Slide 14,

Re: how to handle forms with more than submit button

2007-08-02 Thread Doug B
context_dict.update(button1_helper()) Opps, forgot to actually call button1_helper. Sorry, need sleep :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to

Re: how to handle forms with more than submit button

2007-08-02 Thread Doug B
> thanks doug, this is what I did, but I am not comfortable with it. > those two button do different things, and if they're under one method > on the views it could be ugly, what if I have 4 or 5 submit buttons? Keep in mind there is nothing keeping one view from calling another. def

Re: how to handle forms with more than submit button

2007-08-02 Thread Doug B
As far as I know a form submits to a single url via the action=? specifier. That's just the way an html form works. Each submit button that is part of the form is going to post to the action url in the form. You can override with javascript, but that doesn't make much sense unless you're doing

Re: Recipe / Ingredient Model

2007-08-02 Thread Lucky B
God, 0/2, just do what John proposed, I am not thinking straight right now, what I would give for an edit capability on my emails, I'll spend all of tonight removing my foot from my mouth. On Aug 2, 10:49 pm, Lucky B <[EMAIL PROTECTED]> wrote: > Ok, I've thought about it some more, an

Re: Recipe / Ingredient Model

2007-08-02 Thread Lucky B
the middle-man model. I am pretty sure that's the only way to do it, but I could be wrong. On Aug 2, 10:29 pm, Lucky B <[EMAIL PROTECTED]> wrote: > ack, I missed a few things, the ingredient-quantity measure. not sure > how to do that. ignore my previous message. > > On Aug 2, 10:27 p

Re: Recipe / Ingredient Model

2007-08-02 Thread Lucky B
ack, I missed a few things, the ingredient-quantity measure. not sure how to do that. ignore my previous message. On Aug 2, 10:27 pm, Lucky B <[EMAIL PROTECTED]> wrote: > You're missing just: > ingredients = models.ManyToManyField(Ingredient) > > In your recipe model. > &

Re: Recipe / Ingredient Model

2007-08-02 Thread Lucky B
You're missing just: ingredients = models.ManyToManyField(Ingredient) In your recipe model. If you want a pretty interface in admin (if you're not using newforms- admin) then: ingredients = models.ManyToManyField('Ingredient', filter_interface=models.HORIZONTAL) On Aug 2, 10:13 pm, "Shane

Re: how to handle forms with more than submit button

2007-08-02 Thread Lucky B
create different URLs (and thus different views) for the different buttons and then redirect to wherever you want to go. On Aug 2, 10:13 pm, james_027 <[EMAIL PROTECTED]> wrote: > Hi, > > How do I handle this situation wherein I want different submit button > to call different method on the

Re: Queryset of instances bound to particular ForeignKey

2007-08-02 Thread Lucky B
If I gather correctly you want to see every ModelA that's bound to a particular ModelB b? ModelA.objects.filter(modelBs=b) That gives you what you want. On Aug 2, 7:20 pm, Benjamin Goldenberg <[EMAIL PROTECTED]> wrote: > Hi everyone, > I asked about this earlier today on IRC and

Re: Admin and ManyToManyField

2007-08-02 Thread Lucky B
null=True only affects the database representation, you need to set blank=True. The reason you can do it in the command line is that you can bypass admin's validators through the command line. On Aug 2, 11:08 am, Ramashish Baranwal <[EMAIL PROTECTED]> wrote: > Hi, > > I have a model that has a

Re: ModelMultipleChoiceField doesn't do initial selection

2007-08-02 Thread Lucky B
I think you should be using form_for_instance on the dvd instance instead of the generic form contructor. http://www.djangoproject.com/documentation/newforms/#form-for-instance On Aug 2, 11:14 am, "Kai Kuehne" <[EMAIL PROTECTED]> wrote: > No ideas anyone? :-/

Re: Something like a mini Crystal Reports with Django

2007-08-02 Thread Lucky B
You could try Eclipse BIRT for a WYSIWYG interface. But otherwise you can create a view however you want to report your data doing whatever manipulation you wanted. I don't see what else you would need other than to create a view. On Aug 2, 5:17 am, Mir Nazim <[EMAIL PROTECTED]> wrote: > Anybody

Re: Do I have to send shopping cart data to every template in my app?

2007-08-02 Thread Lucky B
You can create a custom tag, I've never done it myself, but it's in the docs: http://www.djangoproject.com/documentation/templates_python/#writing-custom-template-tags I am sure you can get more help if you need it, but this should get you started. On Aug 2, 12:51 am, Greg <[EMAIL PROTECTED]>

Re: something I really don't know in using manage.py shell

2007-08-02 Thread Lucky B
You should be doing >>> p = Profile.objects.get(id=1)#or .get(1) or one of the many other >>> posibilities filter returns a list of the results, in the case of id=# it probably returns only one, but it's still a list of one member. So in your case it would work if you did this: >>>p=

Re: retaining the data on validation error using newforms

2007-07-31 Thread Doug B
Everything can be changed. Look under auto_id in the newforms docs on djangoproject.com. The default does it exactly the way you seem to be, prepending 'id_' to the field name. If you want to set a class, you need to change the attrs dict on the field's widget. All a newforms field really

Re: caching and "hello username" on each page

2007-07-29 Thread Doug B
You could also make your own render_to_response() function that renders and caches the generic part of the page, and then passes that in as a context for your base layout with the non-cacheable stuff like the username. Or make some of the generic stuff tags that cache themselves using the lower

Re: complex form => Newforms vs template

2007-07-27 Thread Doug B
> So my question is am I missing something or I was just expecting too > much from the newforms? I had similar problems initially, and after hundreds of forms built I still get annoyed every time I have to build a newforms form. On the other hand, I can't really think of a better way to do it

Re: newforms: common constraints

2007-07-26 Thread Doug B
Garg, hit enter too fast. Class MyForm(forms.Form): username = forms.CharField(max_length=12) def clean_username(self): username = self.clean_data['username'] if username == 'bob': raise ValidationError("Bob is not allowed here") return username If

Re: newforms: common constraints

2007-07-26 Thread Doug B
newforms does that, but it's up to you do take care of the details by either subclassing one of the existing fields like this snippet shows: http://www.djangosnippets.org/snippets/115/ Or by making a specially named method on the form definition like this: Class MyForm(forms.Form) username

Re: How to pick a template based on the request object?

2007-07-26 Thread Doug B
Using threadlocals and a custom template loader would probably work, just put your loader first in settings.py. http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser --~--~-~--~~~---~--~~ You received this message because you are subscribed to the

Re: accessing request attributes in templatetags?

2007-07-26 Thread Doug B
Just pass them in as context variables, either the whole thing or just the parts you need. This is kind of a snippet from my current project that might show what I mean. I say kind of because I use a handler object that wraps request and a few other things instead of request directly, but the

Re: DB-Lookup on dynamically created fieldname

2007-07-24 Thread Doug B
Maybe you could do something like this? filterargs = {} filterargs[fieldname] = some value # or for other types of filtering filterargs["%s__istartswith" % fieldname] = somevalue mdl.objects.filter(**filterargs) You might also want to take a look at the function get_model() from

Re: using javascript to update a ChoicesField: getting "not one of the available choices."

2007-07-24 Thread Doug B
Don't use a ChoiceField, but do use the select widget. class TF(forms.Form): blah=forms.IntegerField(widget=forms.Select(choices=((1,'one'), (2,'two'))), initial = 2) post = {'blah': 42} form = TF(post) form should validate. It would be up to you to make sure that the Integer value is

Re: newforms: default Model values

2007-07-24 Thread Doug B
I don't know how others have approached it, but I have a 'settings' file with defaults defined in one place and reference those values via imports in the form file and model file. For values specific for the app, I stick them in the models file. models.py - POST_DEFAULTS =

Re: How to display all my post data

2007-07-23 Thread Lucky B
You could also throw an exception, if you have debug on it'll have everything including the post data. On Jul 22, 11:34 pm, Doug B <[EMAIL PROTECTED]> wrote: > Assuming you just want to debug and are using the dev server you can > just do "print request.POST" and it w

Re: How to display all my post data

2007-07-22 Thread Doug B
Assuming you just want to debug and are using the dev server you can just do "print request.POST" and it will show up on the dev server console. The results aren't all that pretty, but usable. --~--~-~--~~~---~--~~ You received this message because you are

Re: How to use Admin modules in my application

2007-07-07 Thread Doug B
admin != user Atleast that's my view. As tempting as the pretty admin interface might be, I think you would be better off rolling your own form and view for end users. Then you have complete control. Using the form_for_* functions you could have the whole thing done in a few minutes. fetch

Re: Re-rendering same page

2007-06-28 Thread Doug B
Are you sure the request is actually being made, and not ignored by the browser? If you do GETs to the same url with the same parameters (your boolean I assume) the browser will simply ignore the request. I ran into that trying to do some ajax stuff, and ended up appending a timestamp number as

Re: newforms, form.save(), and getting the object I just saved

2007-06-28 Thread Doug B
If you are using the helper functions like form_for_model, form.save() should return the saved object. The helper functions build the save method for you based on the model definition. If you are doing custom forms, it's up to you to make the form.save() method to handle the form->model

Re: Signal for 'ready to receive requests'

2007-06-01 Thread Doug B
I have an event manager that is a bit like a database driven pydispatch combined with a general logging/monitoring app. Embarassingly enough I wrote it before learning about pydispatch and signals. So much for not reinventing the wheel. It keeps track of various events, calls registered

Signal for 'ready to receive requests'

2007-05-31 Thread Doug B
I've been looking around the limited signals documentation and the code hoping to find a signal that basically says 'django is done importing models ready to receive requests', but haven't found it yet. The closest I've found is connecting a receiver to request_started, and then removing that

Re: ManyToMany relation seems to break

2007-05-27 Thread Doug B
Thanks to Malcolm, this was resolved. The problem was because I was trying to use a model before all models had fully been loaded. Unfortunately it was due to my own mistake rather than anything that would help with ticket 1796, but I'm grateful he stuck around to help figure it out anyway.

ManyToMany relation seems to break

2007-05-27 Thread Doug B
I've got a problem I can't figure out, and from the silence in IRC I'm either doing something really stupid or it's as strange as I think it is. I'd appreciate any assistance. For a nice highlighted version try: http://dpaste.com/11163/ """ I'm sorry this is so long. The nutshell version is

Re: reusing python objects

2007-05-24 Thread Doug B
Your proposed solution is exactly what I did. I think the official term is a 'mixin class'. It's worked out really well so far.In my case the mixin class looks for the Event class defined in the model for various settings. In your case they might contain a mapping between your mixin model

Re: newforms + testing

2007-05-23 Thread Doug B
If you put the call to your _users() function in the form __init__() I think it will be what you are looking for. initi s called automatically whenever an instance is created. class MemoForm(forms.Form): -snip- def __init__(self,*args,**kwarg)

Re: newforms + testing

2007-05-23 Thread Doug B
If you put the call to your _users() function in the form __init__() I think it will be what you are looking for. initi s called automatically whenever an instance is created. class MemoForm(forms.Form): -snip- def __init__(self,*args,**kwarg)

Re: newforms + testing

2007-05-23 Thread Doug B
If you put the call to your _users() function in the form __init__() I think it will be what you are looking for. initi s called automatically whenever an instance is created. class MemoForm(forms.Form): -snip- def __init__(self,*args,**kwarg)

Re: A bizarre Forms-via-Templates idea...

2007-05-22 Thread Doug B
The dev server operates much differently than an actual production server. The production server will only evaluate module code once when the module is initially loaded. It doesn't automatically scan for file changes and load files as necessary like the dev server does. If you want file

Re: Solution to multiple models on one form?

2007-05-18 Thread Doug B
My suggestion would be to NOT implement it! I took a similar approach when I was trying to learn python/django, wasted a bit of time, and almost never use the monstrosity I created. I'd have been better off just doing it the django way and/or waiting for newforms to be completed (which may

Re: how to limit foreign key choices by current user?

2007-05-18 Thread Doug B
You can't limit choice like that. The choices specified there are evaluated only when the model is first evaluated (module load time). What you need to do is limit the options displayed to the user via form choices assigned in your view. So you might do something like this (I'm half asleep, but

Re: Way to validate database inserts/updates not associated with forms?

2006-03-07 Thread Mike B
You can still create a Manipulator object to validate your data. Thanks, and I may be clueless here, but it seems as if manipulators don't work within the iterator context.  If I am using an interator to iterate over records that I want to modify and then update using save(), how do I add in a

Way to validate database inserts/updates not associated with forms?

2006-03-07 Thread Mike B
I've been toying around with Django, and I'm trying to figure out the proper way to validate backend data going into the database that doesn't come through a form. In this particular case, the data is coming in off an XML feed and being inserted or updated into a Django model. Can someone point

<    1   2   3   4