Re: Recommendations for a Django development book?

2009-07-21 Thread Dan Harris
You can always check out the free online Django book at: http://www.djangobook.com/ There is the 1.0 version (outdated) and a free web-preview of the 2nd edition available. In addition to books, the documentation for Django is pretty fantastic to learn from for a beginner. This is located at: h

Re: Don't understand ModelForm

2009-07-21 Thread Dan Harris
This may not be helpful but here is how I usually go about processing model forms: class Partner(models.Model): # this is your model, DB fields go in here # This is your model form class PartnerForm(forms.ModelForm): class Meta: model = Partner # This is the view that displays a ne

Re: Don't understand ModelForm

2009-07-21 Thread Dan Harris
What do you mean by having the ID "in" the form? I don't quite understand what you are trying to do. On Jul 21, 4:15 pm, mettwoch wrote: > Ok, I come back to what I wrote before. If the partner already exists > it has an id (primary-key or whatever). If it doesn't exist it has no > id. I'd just

Re: Don't understand ModelForm

2009-07-21 Thread Dan Harris
Oh I gotcha now. Django model forms by default do not represent auto fields (ID's) because it wouldn't make much sense for a user to be able to edit the PK in a form. Having said that, I do understand why you need to be able to see the PK. I shown in my example, I personally prefer to represent

Re: Pass template tags through TextField?

2009-07-22 Thread Dan Harris
That shouldn't be a problem, after all templates are just strings as are textfields. If you have a model with your textfield in it as so: class MyModel(models.Model): template = models.TextField() and you have a view which renders the template defined in the next field def my_view(request)

Re: django-registration and RegistrationFormUniqueEmail subclass

2009-07-22 Thread Dan Harris
The stuff in the brackets are the optional arguments passed to the "register" view. You can read the documentation about the view at: http://bitbucket.org/ubernostrum/django-registration/src/b360801eae96/docs/views.txt Alternatively you can check out the code as well. Cheers, Dan --~--~--

Re: Getting data from Django ModelForm ?

2009-07-25 Thread Dan Harris
Take a peek at the Django forms documentation, specifically the ModelChoiceField and ModelMultipleChoiceField, the docs are at: http://docs.djangoproject.com/en/dev/ref/forms/fields/ These fields allow you to specify a queryset to populate your form select fields, this queryset can be the list of

Re: '_CheckLogin' object has no attribute 'objects' ??

2009-07-25 Thread Dan Harris
Looks just like you have an error in your programming, the name of your view is "Dpatas", then you attempt to later call "Dpatas.objects.filter()" as if Dpatas was a model. The _CheckLogin is coming from your use of the @login_required decorator I would imagine. Hopefully that helps, Dan On Jul

Re: customization using form_class with generic views

2009-07-25 Thread Dan Harris
Assuming that you set_sub_date() function just sets the publish date to when the item was created and easy way to do this is in the model class PressRelease(models.Model): pub_date = models.DateField(auto_now_add=True) That will just set the pub_date to the current date when it is added to t

Re: Trouble getting page to work

2009-08-01 Thread Dan Harris
what error are you getting? On Aug 1, 4:41 pm, cprsystems wrote: > I'm trying to write a simple html page using Django that passes one > variable via a submit button and text line and prints it out to > another hmtl document. I'm having trouble getting it to work. Could > someone explain what I'

Re: Threaded comments on django 1.1

2009-08-07 Thread Dan Harris
Have you checked out: http://code.google.com/p/django-threadedcomments/ I think it is still being updated for 1.1, but it should still work with 1.1. I haven't used it, just know of it's existence. Cheers, Dan On Aug 7, 11:44 am, Alessandro Ronchi wrote: > I must add threaded comments to my

Re: how to deploy Django on the web server?

2009-08-07 Thread Dan Harris
I just wanted to give a shout out as well to webfaction. I used to use my own virtual private server for hosting django stuff, but to cut costs i switched to a webfaction account and it is pretty fantastic. Super easy to set up, if you decide to go that way just drop me and email and i'd be happy

Re: Authenication for django.views.generic Views

2009-04-16 Thread Dan Harris
http://docs.djangoproject.com/en/dev/topics/auth/#limiting-access-to-generic-views hope this helps. Basically you write your own view which calls the generic view after you have done your authentication. On Apr 16, 11:25 am, Col Wilson wrote: > I'm using generic views to render my pages > (djan

Re: Multiple Django versions on one server?

2010-05-03 Thread Dan Harris
virtualenv can be used with mod_wsgi, we are doing so on our production servers. see http://code.google.com/p/modwsgi/wiki/VirtualEnvironments for more information Cheers, Dan On May 3, 8:26 am, Stodge wrote: > I am aware of virtualenv, but can it be used with mod_wsgi. Time to do > some readi

Re: Need subset on Admin interface

2010-06-08 Thread Dan Harris
project.com/en/1.2/ref/contrib/admin/#modeladmin-methods) Hope this helps! Dan Harris dih0...@gmail.com On Jun 8, 10:04 am, onorua wrote: > I have > > class User(models.Model): >     Switch = models.ForeignKey(Switch, related_name='SwitchUsers') >     Port = models.Fore

Re: setting DEBUG=False disables flatpages

2010-06-08 Thread Dan Harris
You need to have a 500.html and a 404.html defined when DEBUG=False. See: http://code.djangoproject.com/ticket/3335 Hope this helps! Dan Harris dih0...@gmail.com On Jun 8, 2:56 pm, adrian wrote: > tracked the problem more down... > > the problem appeared when using own handler404/h

Re: Need subset on Admin interface

2010-06-08 Thread Dan Harris
ModelAdmin. You of course don't have to use JQuery, but it is included by default in the admin and is quite popular. Dan Harris dih0...@gmail.com On Jun 8, 3:17 pm, onorua wrote: > Hello, thank you for your reply! > That's really what I've looked for, some way to prepop

Re: Model inheritance and simple access

2010-06-08 Thread Dan Harris
ve "might" work. And obviously if you have like 5 child classes, this gets ugly very quickly. Dan Harris dih0...@gmail.com On Jun 8, 3:27 pm, John M wrote: > Hmm, that doesn't really get me what I want, it just caches the > related child objects in one SQL query. > > Wh

Re: i can't import newforms(newbie)

2010-06-08 Thread Dan Harris
are you reading? If they are the official Django tutorials that is most likely a bug in the documentation. The documentation on the deprecation of newforms in favor of form is in the Django 1.0 release notes at: http://docs.djangoproject.com/en/dev/releases/1.0/ Cheers, Dan Harris dih0...@gmail.c

Re: django's default id (auto primary key) sorting

2010-06-08 Thread Dan Harris
rks just fine for me. Flipflop the comments to toggle ascending vs descending. Hope this helps, Dan Harris dih0...@gmail.com On Jun 5, 9:16 pm, rahul jain wrote: > Hi Django, > > I tried lots of different ways to get my ids listed in ascending order > (1 - x). But it always disp

Re: assigning data based on a comparison between two tables

2010-06-08 Thread Dan Harris
e than 1 match found") candidates[0].incumbent = True candidates[0].save() Something like that might work for you assuming that the models and stuff are similar. Also, this code is just off the top of my head, so who knows if it will actually work :) Cheers, Dan Harris dih0...@gmail.com

Re: Need subset on Admin interface

2010-06-10 Thread Dan Harris
Sounds about right, glad it's working for you! Dan Harris dih0...@gmail.com On Jun 10, 12:41 pm, onorua wrote: > I did following: > add Media JS for User model (jquery and my own script follows), with > FireBug get the names of HTML id of the elemets I want to process. > Then

Re: error: unsupported operand type(s) for *: 'Decimal' and 'float'

2010-06-10 Thread Dan Harris
'float' You can convert the decimal returned by the form into a float, or convert the floats into decimals and do your math. Converting to decimal is probably more precise. Hope this helps, Dan Harris dih0...@gmail.com On Jun 10, 3:22 pm, Waleria wrote: > Hello.. > > I

Re: select_related() depth when specifying fields

2010-06-10 Thread Dan Harris
a foreign keys with a depth of two. Hope this helps, Dan Harris dih0...@gmail.com On Jun 10, 3:19 pm, Michael Hrivnak wrote: > If I use select_related() on a queryset and specify some attribute names, will > it follow those relationships as far as possible, or does that imply > &q

Re: annotate with query set for distinct values

2010-06-10 Thread Dan Harris
r like: {% for r in res %} {{ r.name }} - {{ r.name__count}} {% endfor %} however there may be duplicated {{ r.name }} Dan Harris dih0...@gmail.com On Jun 10, 5:24 pm, SlafS wrote: > Thanks. > > I've already tried that but this isn't quite what i'm looking for. As >

Re: annotate with query set for distinct values

2010-06-10 Thread Dan Harris
n a list of the form: [{'name__count': 2, 'name': u''}, {'name__count': 1, 'name': u'bbb'}] Hope this helps! Dan Harris dih0...@gmail.com On Jun 10, 5:01 pm, SlafS wrote: > Hi there! > I have a question. If i have a model w

Re: select_related() depth when specifying fields

2010-06-10 Thread Dan Harris
at is how I read the docs, it may not be correct :) Cheers, Dan Harris dih0...@gmail.com On Jun 10, 4:54 pm, Michael Hrivnak wrote: > I read that myself.  I asked the question because it goes on to state that you > can specify down-stream models like this: > > query.select_related(person__

Re: error: unsupported operand type(s) for *: 'Decimal' and 'float'

2010-06-10 Thread Dan Harris
readability thing, you might want to split that giant line of code into a few separate calculations, but that's just an idea! Cheers, Dan Harris dih0...@gmail.com On Jun 10, 3:33 pm, Dan Harris wrote: > The error looks like you are attempting to multiply a decimal by a > float

Re: Writing your first Django app tutorial, part 3 question

2010-06-10 Thread Dan Harris
first-view part of the documentation for more. Cheers, Dan Harris dih0...@gmail.com On Jun 10, 6:30 pm, albert kao wrote: > I try the "Writing your first Django app tutorial, part 3" (http:// > docs.djangoproject.com/en/dev/intro/tutorial03/#intro-tutorial03) with > Django-1

Re: not able to recognize non-default python files in app + project directory

2010-06-10 Thread Dan Harris
els.py file only. If you make a models directory, you have to import all models you want Django to recognize into your __init__.py file within the models directory. Hopefully this makes sense, if not I can try to be more clear. Dan Harris dih0...@gmail.com On Jun 10, 4:46 pm, rahul jain wro

Re: Writing your first Django app tutorial, part 3 question

2010-06-10 Thread Dan Harris
Looks like you haven't created any polls yet, at least not one with an ID of 5. Go into the admin section described in part 2 of the tutorial and make a few polls. Once you've create some you should see polls of IDs 1,2,3 etc show up and the URLs should start to work. Dan Harris dih0...

Re: error: unsupported operand type(s) for *: 'Decimal' and 'float'

2010-06-11 Thread Dan Harris
That looks ok from a code readability point of view, however you will still need to cast the form values to float or cast the float values (i.e. pow(2,2) and pow(2*math.pi*v,2) to Decimals otherwise will you will get an UnsupportedOperation exception. Dan Harris dih0...@gmail.com On Jun 11, 6:58

Re: Model named FOOD_DES shows as "foo d_des" in admin

2010-06-11 Thread Dan Harris
uses with the "db_table" meta option. Please refer to the docs at: http://docs.djangoproject.com/en/1.2/ref/models/options/#model-meta-options for more information. Cheers, Dan Harris dih0...@gmail.com On Jun 11, 1:06 pm, creecode wrote: > Hello all, > > I have a model named FOO

Re: Model named FOOD_DES shows as "foo d_des" in admin

2010-06-11 Thread Dan Harris
hence the space. See: http://docs.djangoproject.com/en/1.2/ref/models/options/#verbose-name for more details. Cheers, Dan Harris dih0...@gmail.com On Jun 11, 2:38 pm, creecode wrote: > Hello Dan, > > Thanks for the info.  verbose_name does take care of the display > problem and I m

Re: Simplification of a DB "query"

2010-06-11 Thread Dan Harris
s: # "show me all objects that are the last meeting before 3 or start betweeen 3pm and 5pm" MyModel.objects.filter(latest_meeting | after_3_and_before_5) Not sure if this is what you're looking for or if it's even right :) Dan Harris dih0...@gmail.com On Jun 11, 4:28 pm, Ces

Re: Controlling access to objects

2010-06-12 Thread Dan Harris
This article might help you out: http://djangoadvent.com/1.2/object-permissions/ Cheers, Dan Harris dih0...@gmail.com On Jun 11, 11:46 pm, Wiiboy wrote: > Hi guys, > I don't know whether the built-in permissions system would be > appropriate here, but I want to control access to

Re: ordering fields in admin form

2010-06-13 Thread Dan Harris
order_by_here') # replace with your ordering method return db_field.formfield(**kwargs) return super(MyModelAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) Hope this helps, Dan Harris dih0...@gmail.com On Jun 13, 8:53 am, backdoc wrote: > This only impacts th

Re: modeling a book repository

2010-06-15 Thread Dan Harris
alling the super class delete. This way when the cascades go through it doesn't have links to next or previous chapters and not everything is deleted. Hope this helps, Dan Harris dih0...@gmail.com On Jun 15, 12:11 pm, Tim Arnold wrote: > Hi, > I have a model for a Book that contains Ch

Re: Question regarding subdomains of a single project

2010-06-22 Thread Dan Harris
looking for. Cheers, Dan Harris dih0...@gmail.com On Jun 22, 10:59 am, Venkatraman S wrote: > On Tue, Jun 22, 2010 at 8:06 PM, M Rotch wrote: > > I'm setting up a website with multiple subdomains, and one thing I > > notice right away (and is expected) is that each subdomain has

Re: Fields validating as optional

2010-06-22 Thread Dan Harris
orm from a model, blank=True inside the models is transformed into required=False for the form. class MyModelForm(forms.ModelForm): class Meta: model = MyModel Hope this helps! Dan Harris dih0...@gmail.com On Jun 22, 4:11 pm, Jonathan Hayward wrote: > What is the preferred way t