Re: Two edit_inlines between the same two models?

2008-07-10 Thread Richard Dahl
While I am not much of a spelunker... why not an attribute of the QM that displays the status (found, killed, etc..)? class Trip(): blah ... qms = models.ManyToMany(QM) class QM(): blah ... status = models.Charfield(max = 30, choices = (('found', 'found'), ('killed', 'killed'))) hth,

Re: Not quite sure how to model the data structure

2008-07-10 Thread Richard Dahl
how about: class Guest(models.Model): first_name = models.CharField(maxlength=30) last_name = models.CharField(maxlength=30) relations = models.ManyToManyField(Relation, related_name = 'guest_relationship') class Relation(models.Model): guest = models.Foreignkey(Guest)

Re: foreign key not being defined in admin interface

2008-07-10 Thread Richard Dahl
t; def __unicode__(self): > > >return self.prot_name > > > > > With prot_name being the primary key field. Is that wrong? > > > > > Allison > > > ps. wow you're quick to respond..thank you > > > > > On Jul 10, 4:56 pm, "Richard Dahl&quo

Re: foreign key not being defined in admin interface

2008-07-10 Thread Richard Dahl
do you have a __unicode__() function for the Protein Model ala: def __unicocde__(self): return ('%s' % (self.name)) -richard On 7/10/08, allisongardner <[EMAIL PROTECTED]> wrote: > > > Sorry about obscure title...don't know what the problem is let alone > its name. > I am inputting protein

Re: Newforms Admin - Overriding the Save Method of an Inline Model

2008-07-02 Thread Richard Dahl
You may be able to do what you want to by overriding the save() function within the model. If you need any information from the form or related object you could pass them as kwargs to save. http://www.djangoproject.com/documentation/model-api/ -richard On 7/2/08, Brian Rosner <[EMAIL

Re: Trouble activating the admin interface

2008-07-02 Thread Richard Dahl
Also ensure that you have imported those models into your apps models.py from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType os some such import statement should be at the top of your models.py -richard On 7/2/08, Brian Luft <[EMAIL

Re: Polymorphic model: many-to-many is not properly resolved

2008-07-01 Thread Richard Dahl
Yes, of course you did, I just didn't read your post quite right, disregard. -richard :) On 7/1/08, Torsten Bronger <[EMAIL PROTECTED]> wrote: > > > Hallöchen! > > Richard Dahl writes: > > > In your example SpecialProcess inherits from Process and Sample > >

Re: Polymorphic model: many-to-many is not properly resolved

2008-07-01 Thread Richard Dahl
In your example SpecialProcess inherits from Process and Sample has a M2M to Process, where should the SpecialProcess come in? Is this what you mean: class Sample(models.Model): processes = models.ManyToManyField(SpecialProcess) If you do this, you should get SpecialProcess from print

Re: combining unrelated tables

2008-07-01 Thread Richard Dahl
Not sure exactly where you are going, but what do you mean by ' Inside views.py it only lets me send 1 queryset to the template' why can't you do something like: render_to_response('Template.html', {'first_qs': Model1.objects.all(), 'second_qs':Model2.objects.all()}) -richard On 7/1/08,

Re: views.py: Always a simple return?

2008-06-25 Thread Richard Dahl
Generally with HTTP, you would configure your server to continue to respond to requests;) Which is exactly what django does anyway. HTTP is a connection based (TCP) protocol, but the connection is closed once the return has been sent. Hence the need to store a 'session' variable in the server

Re: How do I add the user ID to a template?

2008-06-24 Thread Richard Dahl
The 'core' problem as you say, is essentially the core problem of all programming: programs don't write themselves. You have to write appropriate code for what you are trying to do, what does it matter if someone forgets to add the username to the render call, or if someone forgets to add the

Re: psycopg2

2008-06-24 Thread Richard Dahl
Well, in keeping with the spirit of the link referenced, at least its not trac! Seriously, though, psycopg2 is an open source library with a history of working pretty well for what it does. AFAIK there is not a great deal of money behind it, and so they may not have the prettiest or most useful,

Re: How do I add the user ID to a template?

2008-06-24 Thread Richard Dahl
That (or some variation) is the simplest way to do it, although you do not need to attach the entire request object if you do not want to, i.e.: return render_to_response('somepage.html', {'username':request.user.username}) {{ username }} On 6/24/08, Huuuze <[EMAIL PROTECTED]> wrote: > > > A

Re: Multiple fields without manytomanyfield?

2008-06-23 Thread Richard Dahl
I am a bit confused, are you looking for this: class IntegerRelation(models.Model): content = models.IntegerField() class A(models.Model): integers = models.ManyToManyField(IntegerRelation) -richard On 6/22/08, Xan <[EMAIL PROTECTED]> wrote: > > > Hi, > > Suposing you want a model A

Re: retrieving record id after form save

2008-06-23 Thread Richard Dahl
new_obj = form.save() new_objects_id = new_obj.id hth, -richard On 6/23/08, Calvin Dodge <[EMAIL PROTECTED]> wrote: > > > I need to get the id of a record after saving it with form.save(). I'm > not seeing this described in the docs, and haven't dredged anything up > by searching this group. >

Re: Need help encapsulating a form

2008-06-20 Thread Richard Dahl
" % > (reference_name) > >#send_mail(subject, message, email, '[EMAIL PROTECTED]') >request.session['first_name'] = first_name > > > Do you see anything else that can be encapsulated along the same line? > I don't have as much redundancy now, but if this is

Re: Need help encapsulating a form

2008-06-20 Thread Richard Dahl
an Lua.com has been > received.' >message = "Thank you for suggesting %s to us. We'll review > your suggestion and get back to you as quickly as possible." % > (reference_name) > >send_mail(subject, message, email, > '[EMAIL PROTECTED]') >

Re: Need help encapsulating a form

2008-06-20 Thread Richard Dahl
put all of the otherwise duplicative code into its own function within another module. then import that function into your views.py, i.e: at the top of views.py: from formprocessing.py import formprocessor then within formproccessor.py def processemail(email, reference_name): subject

Re: Accessing model from view

2008-06-20 Thread Richard Dahl
You should be able to access it in a template from an instance of a model that uses it via: model_instance_object.ROLES but if you just want to access from the template generically, then yes, you need to pass it to the template. hth, -richard On 6/20/08, diggs <[EMAIL PROTECTED]> wrote: > > >

Re: Accessing model from view

2008-06-20 Thread Richard Dahl
sure, its just python: for r in ROLES: r[0] #retrieves 'Associate' the first iteration r[1] # also retrieves 'Associate' You just need to ensure that ROLES is imported into your views. hth, -richard On 6/20/08, diggs <[EMAIL PROTECTED]> wrote: > > > Hello, > > I've defined a set of

Re: Models advice

2008-06-20 Thread Richard Dahl
While I am not one to insist on 3rd normal form or anything like that, I would recommend you look at normalizing this db a bit. Perhaps you could create a table or two for the companies and contact info, it can be dangerous to limit yourself to one phone number or even one address in many cases.

Re: insert row into ManyToManyField

2008-06-18 Thread Richard Dahl
Couldn't this also be done via: Country(models.Model) name = Char() borders = ManyToMany(CountryBorders) CountryBorders(models.Model): border = models.FK(Country) length = models.PosIntField() With this you could have: Country: name: Germany borders: France/1000Km,

Re: iterate over alphabet in template

2008-06-17 Thread Richard Dahl
I would probably just pass in a python list with all of the letters in the alphabet, then just {% for l in alphabet_list %} ... -richard On 6/17/08, M.Ganesh <[EMAIL PROTECTED]> wrote: > > > Hi All, > > I am relatively new to both python and django. Please help me to do this : > > {% for letter

Re: HTML Escaping JSON data?

2008-06-16 Thread Richard Dahl
What exactly are you trying to do? Are you worried about people entering html into the form fields and having that saved to the database? If so, Django's ORM escapes this for you when saving to the DB. you can use jQuery's ajax functions to submit the form, and do normal form validation with

Re: Form Validation

2008-06-11 Thread Richard Dahl
Just an idea, not sure if it will work for you as I don't know a whole lot about how it works, but wouldn't setting unique_together on the Relation class for owner and pet accomplish what you want? The validation happens at the DB level, but I believe it propogates back to the form. hth, -richard

Re: Total newbie question

2008-06-10 Thread Richard Dahl
I would start with 'Dive into Python' or 'How to think like a computer scientist in python' to gain familiarity with basic python concepts. -richard On 6/10/08, Pedro Cora <[EMAIL PROTECTED]> wrote: > > > First of all, sorry if i'm making a question that should appear a lot > here. > > I'm a

Re: HELP: Foreign keys, models, and querysets

2008-06-09 Thread Richard Dahl
from: http://www.djangoproject.com/documentation/db-api/ Backward If a model has a ForeignKey, instances of the foreign-key model will have access to a Manager that returns all instances of the first model. By default, this Manager is named FOO_set, where FOO is the source model name,

Re: Django Suitable for this?

2008-06-08 Thread Richard Dahl
In my opinion, it shouldn't matter what type of web app you are creating, Django is a framework that can be used to develop any kind of app you can imagine. That being said, Django was designed for a particular use and has been tailored for that use, deviating significantly from that

Re: use my own widgets when creating a form out of a model

2008-06-05 Thread Richard Dahl
I have implemented this by looping through the form fields in a generic form creation function. Not sure if it is the 'proper way' but it works very well for me. -richard On 6/5/08, Wim Feijen <[EMAIL PROTECTED]> wrote: > > > Hi Richard and Rishabh, > > Thanks for your help. > > Actually, I

Re: use my own widgets when creating a form out of a model

2008-06-04 Thread Richard Dahl
from:http://www.djangoproject.com/documentation/newforms/#widgets class CommentForm(forms.Form): name = forms.CharField( widget=forms.TextInput(attrs={'class':'special'})) url = forms.URLField() comment = forms.CharField(

Re: Philosophical Django Questions

2008-05-30 Thread Richard Dahl
As far as the first question, I would create my own group model. My reasoning is pretty simple, I create models based on functionality or purpose of the object. auth.groups is essentially used to assign permissions to users, you are really looking to associate users with other users. So while it

Re: Problem State/City Relations

2008-05-30 Thread Richard Dahl
Usually this would be done with a javascript function. You could display the form but have the city field disabled until a state was chosen and then (probably with an async call) populate the city field with a list of relevant cities. To just use server side validation for this you would have to

Re: order_by foreign key problem

2008-05-29 Thread Richard Dahl
>raise errorclass, errorvalue > OperationalError: (1054, "Unknown column > 'itemengine_gear.generic_info__hits' in 'order clause'") > > The template chokes the same way trying to access the object... > I shouldn't have to change my code? > > rob >

Re: order_by foreign key problem

2008-05-29 Thread Richard Dahl
http://www.djangoproject.com/documentation/db-api/ contains the info you want. Try this: Gear.objects.select_related().order_by('generic_info__hits') you could also set the order_by in the Meta of Item to hits and then you could just do: Gear.objects.select_related().order_by('generic_info')

Re: ModelChoiceField, Cascading Selections

2008-05-29 Thread Richard Dahl
Two options I can think of quickly: 1. in the __init__ of the form, see if a value has been passed in for the League and School and only if there is none, create the queryset as described. 2. Do not use a model form to create the initial form, just use a simple template and the javascript you have

Re: Just getting started

2008-05-29 Thread Richard Dahl
I have been working on an app that enables the completion of IT security assessments. A version of it that I used 2 years ago did allow remote completion of the assessments and I faced this same problem. I was not comfortable using the django development server locally (primarily because of the

Re: hijacked python-pgsql page?

2008-05-28 Thread Richard Dahl
initd.org is having problems with thier Trac implementation. -richard On 5/28/08, Andrew D. Ball <[EMAIL PROTECTED]> wrote: > > > Good afternoon. > > When I follow the following link from the Django > Book, v1.0 to information about using Django > with PostgreSQL, I get redirected to a rant: >

Re: Enforcing case sensitivity at Model level

2008-05-27 Thread Richard Dahl
1. Create a custom save() method on the model that took the contents of the field in question and called .lower() on the string - If you simply want to make sure only lowercase letter are saved to the database. 2. Create a custom field (subclass models.CharField?) that only accepted lowercase

Re: ManyToManyField, add custom column

2008-05-27 Thread Richard Dahl
You can do this with an intermediate table: class Fruit(models.Model): name = models.CharField() def __unicode__(self): return ('%s' % (self.name)) class FruitItem(models.Model): fruit = models.ForeignKey(Fruit) number = models.IntegerField() def __unicode__(self):

Re: Difference between using postgresql_psycopg2 vs postgresql

2008-05-24 Thread Richard Dahl
I am not sure about any specific differences, but psycopg2 is what I believe to be recommended by initd.org, although there seems to be a problem with their Trac so I could not confirm. I originally (2 years ago) setup up Django with psycopg1, but when I rebuilt my development

Re: Generic ManyToMany - any code?

2008-05-24 Thread Richard Dahl
Not sure if there is a better way (suggestions are appreciated), but I just use the GenericForeignKey i.e.: class Asset(models.Model): content_type = models.ForeignKey(AssetType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type',

Re: dynamic filtering (with jQuery)

2008-05-23 Thread Richard Dahl
Firebug is where you will get django's errors, if you are using an async call to django (AJAX, XHR, etc..) -richard On 5/23/08, Peter Rowell <[EMAIL PROTECTED]> wrote: > > > > The debug information is available from firebug. You will see the > reuest, > > right click on it and select 'Open in

Re: storing a list of arbitrary generic objects in a db field

2008-05-23 Thread Richard Dahl
This could also be done with Generic Relationships: http://www.djangoproject.com/documentation/models/generic_relations/ I use this for similiar object references. I also sometimes use intermediary tables between the base model and the generic_relationship to limit the types of objects that can

Re: dynamic filtering (with jQuery)

2008-05-23 Thread Richard Dahl
The debug information is available from firebug. You will see the reuest, right click on it and select 'Open in New Tab' -richard On 5/23/08, Joseph <[EMAIL PROTECTED]> wrote: > > > Peter: Thanks for the reply. > > I do have DEBUG=True. > I have tried both 1/0 and assert false; but both times I

Re: Forms from Database Tables with choice selects.

2008-05-22 Thread Richard Dahl
This is still pretty WET for my tastes, but I do not completely understand your requirements. Programming is after all an art and a science. I have a tendendcy to normalize things as much as I feel is reasonable, perhaps it is more than you require. I would at least consider something like the

Re: Forms from Database Tables with choice selects.

2008-05-21 Thread Richard Dahl
I would caution you to think in the terms of the data storage (models) separately from data entry (forms via views). Most likely you want a class Person which would have a field for title. Maybe the title field is a FK to the Title model, maybe it is a charfield with or without 'choices'

Re: Reusable models?

2008-05-21 Thread Richard Dahl
Why not just define your base models in a Module in your import path called basemodels.py and import the specific base models you need into the requisite app. You could then use model inheritance to add the specific fiddly bits required for that app. It is just python after all. Am I

Re: relationships problem

2008-05-21 Thread Richard Dahl
I am not really sure exactly what you are trying to accomplish here, if you want to 'create a load of Places based on what is in RawPlaces but with a resource' wouldn't a FK or M2M (depending on your cardinality requirements) relationship to RawPlaces within Resource simplify this process? I am

Re: "request"object within models.py

2008-05-19 Thread Richard Dahl
James, Thanks, this is great. I never made this connection before. I have been using threadlocals for a while (to implement a custom manager with role-based access). Since the start I have been passing a users role as a kw argument in to the Manager via the shell for testing, and until

Re: "request"object within models.py

2008-05-19 Thread Richard Dahl
how do you pass the request object to models? -richard On 5/19/08, James Bennett <[EMAIL PROTECTED]> wrote: > > > On Mon, May 19, 2008 at 3:24 PM, enri57ar <[EMAIL PROTECTED]> wrote: > > How access to request object within models ? > > Pass it as an argument the same as any other value. Magical

Re: questions about templates within templates and ajax pop-up window

2008-05-19 Thread Richard Dahl
at more clear > so please keep'em coming > > On May 19, 9:33 pm, sebey <[EMAIL PROTECTED]> wrote: > > ok but I may want enable it and disable it and change the message form > > time to time which is why I would like it go though django > > > > On

Re: questions about templates within templates and ajax pop-up window

2008-05-19 Thread Richard Dahl
<[EMAIL PROTECTED]> wrote: > > > ok but I may want enable it and disable it and change the message form > time to time which is why I would like it go though django > > On May 19, 5:27 pm, "Richard Dahl" <[EMAIL PROTECTED]> wrote: > > There are a number

Re: "request"object within models.py

2008-05-19 Thread Richard Dahl
http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser -richard On 5/19/08, enri57ar <[EMAIL PROTECTED]> wrote: > > > How access to request object within models ? > > > from django.contrib.auth.models import User > > Class Message(models.Model): >message = ... >user_id =

Re: questions about templates within templates and ajax pop-up window

2008-05-19 Thread Richard Dahl
There are a number of ways to do this, you do not need a separate template within your template. You do not even need to use AJAX, as you seem to be wanting to return both the main content and the 'message' in one response.) You could simply wrap your message html in a div that is hidden and use

Re: How to add an object with relations to other objects

2008-05-17 Thread Richard Dahl
. How I get B related with A? (Ok, by setting the attribute, > but...) How can I do that by using form_for_model() according to my > database model? The User don't have the choice to manipulate the ID of > A or something like that. There shouldn't be a field for the ID! > > On 16 Mai, 22:52

Re: How to add an object with relations to other objects

2008-05-16 Thread Richard Dahl
For the first question, the db-api doc should provide this and more information, as I am not sure I completely understand, but here goes (assuming the following models): class B(models.Model): attribute = char()... class A(models.Model): attribute = char()... bs = m2m(B) in your

Re: Add column to generated ManyToMany table and access from admin

2008-05-16 Thread Richard Dahl
I do not think that admin currently supports this, but I could be wrong. but here are two ways to accomplish it. class Item(models.Model): name = models.CharField(max_length=30) class ItemOrder(models.Model): item = models.FK(Item) order = models.int() def __unicode__(self):

Re: Keeping track of which user did what

2008-05-16 Thread Richard Dahl
This can be done with the threadlocals middleware: http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser On 5/16/08, Chris Farley <[EMAIL PROTECTED]> wrote: > > > Django has that nice "auto_add=True" property you can set on a model's > field. I have two fields in my models called

Re: encrypting form data

2008-05-15 Thread Richard Dahl
Forgive my feeble mind, but I am trying to understand, what is the point of substituting 'walewadu' for 1 or 2 or 3855? What security does this provide? -richard On 5/15/08, Norman Harman <[EMAIL PROTECTED]> wrote: > > > Gabriel wrote: > > Mike Chambers gmail.com> writes: > > > >> > >> I am

Re: encrypting form data

2008-05-15 Thread Richard Dahl
e first record with a high PK, and keep the competition guessing as to how many records you have:) -richard On 5/15/08, Norman Harman <[EMAIL PROTECTED]> wrote: > > Richard Dahl wrote: > > Mike, > > I concur with jonknee, the attribute 'hidden' on a form field simply >

Re: encrypting form data

2008-05-15 Thread Richard Dahl
am also not concerned about spam, but rather just dont want to expose > raw database ids to the public. > > mike > > Richard Dahl wrote: > > Mike, > > I concur with jonknee, the attribute 'hidden' on a form field simply > > tells a browser that is following the s

Re: encrypting form data

2008-05-15 Thread Richard Dahl
The CSRF middleware probably would not provide a solution for this problem. It sets a hidden field with a value that is derived from hashing the session id with a secret, but I do not believe it sets a unique key per form. As long as the session was valid (assuming the app in question is using

Re: encrypting form data

2008-05-15 Thread Richard Dahl
Mike, I concur with jonknee, the attribute 'hidden' on a form field simply tells a browser that is following the standards not to display it. The form field and all of the data within it is still sent via http. Any script or proxy (i.e. webscarab) or other mechanism such as a sniffer can get at

Re: encrypting form data

2008-05-15 Thread Richard Dahl
I am not sure what you mean by 'passed through the form', are you reffering to some sort of hidden form-field? I am not sure exactly how encryption of these two fields is going to help you. If the form processing view is publicly available, and these two values are availble to a user (or

Re: Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Richard Dahl
A third alternative is to use a GenericForeignKey. Although this may add too much complexity. Put the GenericForeignKey in a model called PhotoTag and create a M2M relationship between it and Photo and use it to select either a Place or a UserProfile, i.e. class PhotoTag(models.Model)

Re: Django with Ajax

2008-05-09 Thread Richard Dahl
<[EMAIL PROTECTED]> wrote: > > On 5/9/08, Richard Dahl <[EMAIL PROTECTED]> wrote: > > > > I am not sure what javascript library you are using based on the code > > Google maps. GXmlHttp is just like XmlHttpRequest > > Now I have this in my view: > >

Re: Django with Ajax

2008-05-09 Thread Richard Dahl
I am not sure what javascript library you are using based on the code snippet, but you seem to be looking for a javascript object to be returned that contains XML. What you are returning is simply the text 'hello world' as a plain vanilla http response. You need to return the type of object

Re: /admin Cross-Site Scripting (XSS) issue!

2008-05-07 Thread Richard Dahl
On Wed, May 7, 2008 at 3:18 PM, Richard Dahl <[EMAIL PROTECTED]> wrote: > > If I said that this condition is indicative of an XSS attack vector I > > may as well say that Apache is vulnerable to a Denial of Service > > attack because 'after I ran apachectl stop, I co

Re: Custom Widget with jQuery?

2008-05-07 Thread Richard Dahl
, Kevin Monceaux <[EMAIL PROTECTED]> wrote: > > -richard, > > On Wed, 7 May 2008, Richard Dahl wrote: > > > I am not sure exactly what you mean by 'not step on each others toes' > > What exactly are you concerned with? You could very easily have a form > > w

Re: /admin Cross-Site Scripting (XSS) issue!

2008-05-07 Thread Richard Dahl
Bennett <[EMAIL PROTECTED]> wrote: > > On Wed, May 7, 2008 at 2:51 PM, Richard Dahl <[EMAIL PROTECTED]> wrote: > > Excellent, good catch, when logged out it does indeed display the > > alert, I image it has to do with the 'next' property, which is not, I > > be

Re: /admin Cross-Site Scripting (XSS) issue!

2008-05-07 Thread Richard Dahl
Excellent, good catch, when logged out it does indeed display the alert, I image it has to do with the 'next' property, which is not, I believe, escaped, as it is not entered into the DB or presented to any other user. So again, it begets the question: How is the XSS attack possible? WARNING!

Re: Custom Widget with jQuery?

2008-05-07 Thread Richard Dahl
I am not sure exactly what you mean by 'not step on each others toes' What exactly are you concerned with? You could very easily have a form with 4 phone number fields: home, office, mobile, fax; using jQuery's .class selector i.e. $(".phone").mask("(999)999-"); you could find all of the

Re: /admin Cross-Site Scripting (XSS) issue!

2008-05-07 Thread Richard Dahl
I don't understand how this becomes an XSS vulnerability, XSS attacks work by having malicious scripts executed by another user. Key word being 'another'. If this works (it gives me a 404) this is an example where you can XSS attack yourself, but there is no reasonable what to necessarily

Re: Empty Result set

2008-05-06 Thread Richard Dahl
try this: result_set = Model.objects.all() if result_set: result_set has data else: result_set is empty On 5/6/08, jwwest <[EMAIL PROTECTED]> wrote: > > What's the preferred method of checking to see if a result set is > empty in a view? For instance, I'm writing blog software and have a

Re: Few things ive been wondering

2008-05-05 Thread Richard Dahl
see comments inline... On 5/5/08, phillc <[EMAIL PROTECTED]> wrote: > > there has been a few things that i feel have been holding back from > making my code structure/process better. i was hoping someone could > help me on some of these questions. > > first: > > How does one develop tests

Re: Access Control List

2008-05-01 Thread Richard Dahl
The documentation says that it is not provided by the auth system and not built into the admin, but it may be possible. One thing you should try is to build a custom manager for your model and use threadlocals (search the archives for this) to enable this. Something like: class

Re: form_for_model and accessing foreign object attribute

2008-04-28 Thread Richard Dahl
You are having trouble because the form does not contain a Manager object, it contains the primary key of a related Manager object. try this: m = Manager.objects.get(pk=form['manager']) send_mail( 'Software Request', message, sender, m.email) -richard On

Re: Intermediary Triple Join Table?

2008-04-28 Thread Richard Dahl
Based on what you have described I see no reason to tie a persons sports role to them directly, by doing something like what I suggest below, you tie a person to a role only when they use that role (during a game). If you think about it, this represents real life a bit more accurately. I played

Re: ORM questions...I'm not smart

2008-04-17 Thread Richard Dahl
cjl, Essentially you need metatables that can describe the attributes relatable to your main models. I built a proof of concept db backend last year for a 'Database Application for the Management of Information related to all Things' , (codenamed: DAMIT) but decided that while possible,

Re: Dynamically limiting choices in admin.

2008-04-14 Thread Richard Dahl
This is where I would suggest you rethink your data model. Is there a reason to link Article to both Issues and Magazine? Why not something like: Issues has FK (magazine) to Magazine Articles has FK (issue) to Issues Issues could be configured to return its magazine.title and self.issue_number

Re: cannot resolve keyword mmtype__eq into field

2008-04-14 Thread Richard Dahl
try this pdata = myfile.objects.filter(mmtype__exact="W") hth, -richard On 4/14/08, Jaap <[EMAIL PROTECTED]> wrote: > > > django version 0.96.1 on windows xp home. > > error is caused by statement in view: > pdata = myfile.objects.filter(mmtype__eq="W") > > where the model is: > > mxt = ( >

Re: chained many-to-manys

2008-04-14 Thread Richard Dahl
How about: a = A.objects.get(pk=1) c = C.objects.filter(Q(a__exact = a) | Q(b__a__exact = a)).distinct() hth, -richard On 4/14/08, Jeff Gentry <[EMAIL PROTECTED]> wrote: > > > I have a setup that I figured I could just crib off of the > User/Group/Permission code because the setup is

Re: ModelForms: overwriting a field using parameters from the form constructor

2008-04-14 Thread Richard Dahl
You could do something like this: f = forms.form_for_model(modelname) f.base_fields['fieldname'].queryset = (query_based_on_variable) I automatically do this for a number of forms (to enforce role-based access) by looping through the base fields: get_form(model_type, r): f =

Re: Article Count

2008-04-04 Thread Richard Dahl
I think it depends on exactly what article_count is. Is it the number of views of the article? The total number of articles? The number of articles related to this article? I am just not sure what you are trying to accomplish. -rfd On 4/4/08, Chris <[EMAIL PROTECTED]> wrote: > > > If I have an

Re: is model related

2008-02-11 Thread Richard Dahl
I use something like this in a function that creates forms for most of my models with some special processing based on related fields: for n in object_instance._meta.fields: if n.verbose_name == 'RELATED_FOREIGNKEY_MODEL_VERBOSE_NAME': #Model has FK relation for n in

Re: Filter changing table name?

2008-02-07 Thread Richard Dahl
The join table is created by django when you do a syncdb, however if the table with the M2M relation in it is already present (as in your case) the join table will not be created. This appears to me to be your problem. If you want it to be a m2m relation, you can create the join table

Re: Query for cascading children to a parent

2007-10-08 Thread Richard Dahl
I have a model class 'Organization' with a parent and I do this with a method get_child_orgs: get_child_orgs(self): child_orgs = [] co = Organization.objects.filter(parent__exact = self) for c in co: child_orgs.append(c) gc = c.get_child_orgs()

Re: Linking dropdowns using newforms

2007-10-03 Thread Richard Dahl
I have used both mochikit and yahoo YUI for this, both of them work well. JQuery show a great deal of promise as well although I have never used it. -richard On 10/3/07, Emmchen <[EMAIL PROTECTED]> wrote: > > > @ Hraban - Thank you for your reply. > > Yes, I want to display up to four columns.

Re: Does setting a session cause a redirect?

2007-10-03 Thread Richard Dahl
I can't see why that would cause a redirect, it is hard to diagnose a problem without seeing the code or the server logs. Is the get request for the same URL? On 10/3/07, Rob Hudson <[EMAIL PROTECTED]> wrote: > > > I'm working on an advanced search feature for a website and am using >

Re: Help accessing user.

2007-10-01 Thread Richard Dahl
Django works just like any other web app. It is stateless. There is no way of passing the object from one view to another. You must enable sessions in order to store the user associated with any given login. Refer to the django documentation for sessions. -richard On Oct 1, 2007, at 9:46

Re: test models

2007-10-01 Thread Richard Dahl
My approach to a similar problem is to instantiate a user within my test setup and pass that user to the model.save function. i.e class Device(models.Model): foo = models bar = models def save(self, user=None): model_instance = save_function(self, user)

Re: What's going on with Row Level Permissions?

2007-10-01 Thread Richard Dahl
Aryko, I didn't need row-level permissions so much as I needed role-based permissions, sort of the same thing but not exactly. I rolled my own. I do not believe the rlp branch is being actively maintained, but cannot say for sure as I have not looked into it in a while. Essentially I associate

Re: login() doesn't log me in

2007-09-28 Thread Richard Dahl
Alper, Do you have sessions enabled? see http://www.djangoproject.com/documentation/authentication/#authentication-in-web-requestsfor details. As you are not doing anything special with your login function, have you considered using the @login_required decorator on the dashboard view? I know

Re: what is wrong with my New Forms code

2007-09-27 Thread Richard Dahl
It is hard to see with the indentation as it is, but it seems you are not returning an http response if the 'if id is none:' You are building the form for model, but it doesnt look like it is returned. The bottom line seems to be indented to correlate to the if request.method not the

Re: about auth

2007-09-27 Thread Richard Dahl
come up with. -richard On Sep 27, 2007, at 2:38 PM, Lic. José M. Rodriguez Bacallao wrote: > I'll do that > > On 9/27/07, Richard Dahl <[EMAIL PROTECTED]> wrote: > There is a row-level-permissions branch, but I do not believe it is > actively being developed at this time. I wr

Re: about auth

2007-09-27 Thread Richard Dahl
There is a row-level-permissions branch, but I do not believe it is actively being developed at this time. I wrote my own role-based permission system and integrated it into all of my models that require it. I have not attempted to integrate the permission system into the admin interface though.

Re: Validation after form.save(commit=False) - newforms

2007-09-26 Thread Richard Dahl
Off the top of my head, how about something like this: form_data = request.POST form_data['domain_id'] = domain_id form = DNSRecordForm(form_data) if form.is_valid(): form.save() I think you should get the idea. Obviously the DNSRecordForm will have to have the domain field in it.

Re: One-To-Many Ordering ?

2007-09-26 Thread Richard Dahl
Within the Meta class of the Model you can set the default ordering of objects when getting a list of them. class Meta: ordering = ['field_to_order_by'] -richard On 9/26/07, Vitaliy <[EMAIL PROTECTED]> wrote: > > > For example i have this model: > > class Post(models.Model): >#some

Re: What's the best way to handle big sets of data?

2007-09-25 Thread Richard Dahl
. -richard On 9/25/07, Bruno Tikami <[EMAIL PROTECTED]> wrote: > > Hi Richard, > > I'm more concerned with the query response time... > > thanks for your fast reply = ) > > On 9/25/07, Richard Dahl < [EMAIL PROTECTED]> wrote: > > > > Bruno, > > It is

Re: What's the best way to handle big sets of data?

2007-09-25 Thread Richard Dahl
Bruno, It is difficult to advise based on the information provided. Not sure exactly what you are concerned with, postgres database size? query response time? network transfer time? All of the above? Each of these impacts can be dealt with differently. Perhaps if you provided some detail on

  1   2   >