another 6 hour code jam - tagmindr.com

2007-10-10 Thread anders conbere

Just a quick announcement, though created without any for knowledge of
djangogigs, a group of us got together last Saturday with the proposal
of creating a fully functional web app from idea to production in 6
hours.

We were given the seed idea of an app that would help you remember
things you had tagged by reminding you at a certain date, and the
result was tagmindr. You give it a username that you use around the
web, and it will check ma.gnolia.com, de.licio.us and flickr for
anything tagged tagmindr, and then secondarily search those entries
for any tags of the form "remind:". When that date comes up, it
puts that item in a public rss feed that you can be watching.

http://tagmindr.com/

you can read more about the event at my blog

http://anders.conbere.org

or leo's blog

http://www.embracingchaos.com/2007/10/tagmindr-use-de.html

Anyway the event was a blast, we finished in about 6 and half hours,
and while the prod version only has support for delicious and magnolia
the flickr support was easy to add and is in svn.

That's all :-D

~ Anders

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



Re: Is it really this hard?

2007-05-15 Thread anders conbere

further there is the great save_instance function that when coupled
with using the __dict__ attribute makes doing custom form to model
manipulation really easy.

save_instance(form_instance, model_instance)

will update the model instance with the form data

~ Anders

On 5/15/07, John Matthew <[EMAIL PROTECTED]> wrote:
> Ah Ha, now we're getting somewhere!
>
> Let me start searching for that, thank you!!
>
> John
>
>
> On 5/15/07, James Bennett < [EMAIL PROTECTED]> wrote:
> >
> > On 5/15/07, John M < [EMAIL PROTECTED]> wrote:
> > > I wish the custom form option would allow me to bind to a data object,
> > > based on field names being the same, that way I could have fields in
> > > the form that aren't bound and ones that are, without a lot of hassle.
> >
> > To do that you want to get a dictionary out of the object, which means
> > using the '__dict__' attribute. For example:
> >
> > my_obj = MyModel.objects.get(pk=1)
> > form = MyForm(my_obj.__dict__)
> >
> > The form is smart enough to take a dictionary-like object and pull out
> > the values it wants; that's how it works with request.POST, for
> > example.
> >
> > --
> > "Bureaucrat Conrad, you are technically correct -- the best kind of
> correct."
> >
> >
>
>
>  >
>

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



Re: Is it really this hard?

2007-05-15 Thread anders conbere

As far as I know the officially recommended way of accomplishing this
while still using the form_for_* helper functions is through the use
of a formfield_callback, a function that takes field instances and
mucks with them.

def form_callback(field, **kwargs):
if field.name == "field_name":
return None

my_instance = MyClass.objects.get(pk=x)
form = form_for_instance(instance, formfield_callback= form_callback)

will remove the field named "field_name" from the form

~ Anders

On 5/15/07, John Matthew <[EMAIL PROTECTED]> wrote:
> James, thanks for the quick reply!
>
> Ok, I like what you have there, but it doesn't solve the problem of when I
> want to edit an existing record, how do I use the customform?  I guess I'm
> just missing something super simple here, no?
>
> I would think code like
>
> instance = objects.get(id=1)
> form = OrderForm(
> instance)
> does this get me the form filled with the data from instance?
>
> Thanks
>
>
> On 5/15/07, James Bennett <[EMAIL PROTECTED]> wrote:
> >
> > On 5/15/07, John M <[EMAIL PROTECTED]> wrote:
> > > When I put up the form for order, I don't want the Customer (foreign
> > > key) to appear.  I've not seen anything on the forum that shows you
> > > can easily eliminate a field from the form?
> >
> > In general, form_for_model and form_for_instance are for when you just
> > want "form for this thing" and don't care about fine-grained control
> > of the fields. When you do want fine-grained control of the fields, a
> > custom form is the way to go.
> >
> > > Unless I'm missing how to create a custom form, bind it to the DB's
> > > data and use it like I can form_for_instance() and form_for_model().
> >
> > Something like this is what you're looking for, I think:
> >
> > http://dpaste.com/10396/
> >
> > --
> > "Bureaucrat Conrad, you are technically correct -- the best kind of
> correct."
> >
> >
>
>
>  >
>

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



Re: Model subclassing

2007-05-15 Thread anders conbere

On 5/15/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
>
> On Mon, 2007-05-14 at 16:13 -0700, Joe wrote:
> > I was wondering what the status of this is? I know that it broke a
> > while back with the introduction of magic object removal, and has been
> > in the pipeline since. I just tested it out on my recent SVN checkout,
> > and it seemed to create the tables in the database in the way that one
> > would expect. However I am scared to start using it in case something
> > goes awry with the model managers or some other eventuality.
> > Is it safe to use?
>
> It completely doesn't work. You will end with the wrong managers on the
> sub-classed models. Please be patient a little longer and use one-to-one
> relations in the interim.

Are one-to-one's recommend again now? (last time I looked they were
recommending foreignkeys with unique=True instead)

~ Anders

>
> Regards,
> Malcolm
>
>
>
> >
>

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



Re: Using newforms to show a single form for multiple models

2007-05-14 Thread anders conbere

just remember that a form instance is completely unaware of the model.
 So in your view you'll want to create a form instance for your list
and a form instance for a list item (you can either work on the form
instances now in the view to provide unique names for each input or in
the template later). In the template you display your forms just like
you would otherwise.


{{ list_form.as_ul }}
{{ item1_form.as_ul }}
{{ item2_form.as_ul }}

or perhaps more efficients

{{ for item in item_forms }}
{{ item.as_ul}}
{{ end for}}

as I mentioned before you could also write out each form by hand in
the template to ensure each input had unique names.

~ Anders

On 5/13/07, Brad Fults <[EMAIL PROTECTED]> wrote:
>
> I'm in a situation where I have a List model class and a ListItem
> model class. The ListItem class has a ForeignKey to the List class
> with `edit_inline=models.STACKED, num_in_admin=10`. In the admin
> interface for adding a new List, this is represented perfectly: it
> shows the fields for the List object and 10 sets of fields for the
> ListItem objects.
>
> How would I replicate this same form setup (1 List, 10 ListIems) using
> newforms in my app? I looked at the admin code on the newforms-admin
> branch, but it's very genericised and dense. I'm thinking there's a
> simple way to accomplish this, but it's not jumping out at me after
> reading the docs.
>
> I'd appreciate some pointers in the right direction.
>
> Thanks in advance.
>
>
> >
>

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



Re: adding XSLT templating to Django

2007-05-12 Thread anders conbere

On 5/12/07, Nic James Ferrier <[EMAIL PROTECTED]> wrote:
>
> Eugene Morozov <[EMAIL PROTECTED]> writes:
>
> >> - there is proper separation between data and style, my JSON doesn't
> >>   include any stylistic information, only stuff that describes the data
> >
> > I still think that your example is not the best. "div" and "span" has
> > no semantic meaning, they're just HTML placeholders.
>
> Well, ok. The reason for them is that you need them for structure. It
> doesn't make sense to use another tag for some arbitary POSH.
>
>
> >> - you get to use XSLT to turn the JSON into anything you want... you
> >>   need Atom from a resource as well as HTML? Just have 2 different
> >>   stylesheets but the same JSON.
> >
> > I think it is possible with plain Django templates, too. Just define 2
> > different templates.
>
> But then you're doing the python logic bits (for example, serializing
> a seqence) more than once. With mine you only do the programming-y
> bits once and then use XSLT to transform to whatever. The templates
> are very simple then. I've used this approach in a couple of
> frameworks.

I'm not sure I see the benefit of this approach to the typical django style.

def my_view(request, template):
context = {'some_list': ClassOne.objects.all(),
  'some_other_list':
ClassTwo.objects.filter(blah='whatever'),
  }
return render_to_response(template, context)

now I can pass the view any template I want, and it will send that
contex to it. This template could very well be an XML document or a
Latex document or whatever, it doesn't matter.

In your example I would need to write an XSLT to transform the XML
created into X. in the django way you you explicitly designate X.

Creating an XSLT to do that is fine and all but it seems to add a
layer of indirection, and one more added complexity to an already
simple solution.

 ~ Anders
>
> > Your small framework could be really useful in some situations, I was
> > just thinking about how to apply my XSLT knowledge to ease web
> > development tasks. But I think that need better examples really
> > showing benefits of XSLT approach. I was turned off by those HTML
> > elements in JSON data immediately. Maybe this is just my personal
> > opinion.
>
> Maybe... I'm not sure what upsets you about them really.
>
> The exact language you use is up to you... you can put whatever you
> like in and it'll get turned into XML.
>
> For example, this would output something like ATOM:
>
>   tfxslt.send_json(HttpResponse(),
>   {"feed":
> [{"author":
>   {"email": "[EMAIL PROTECTED]"}},
>  {"published": "Sat May 12 22:57:26 BST 2007" },
>  [{"item":
>{"summary": "a bit about this item"}}]]},
>   "atom")
>
> And of course... if you've got anything that can serialize any other
> data structure to JSON then you can use that as well.
>
> I'm really busy actually using my stuff at the mo... I'm hoping to try
> and post it over this weekend on snippets.
>
> --
> Nic Ferrier
> http://www.tapsellferrier.co.uk
>
> >
>

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



Re: Saving Objects from Models??

2007-05-10 Thread anders conbere

Paper_UserReg(request.POST['username'],request.POST['password'],request.POST['name_of_author'],request.POST['email_of_author'],request.POST['college_name'],int(request.P
OST['phone_of_author']),None)

That is NOT sanitized data, and if you think that putting them in
hidden fields in some way prevents other data from being posted your
sorely mistaken. ALL data coming from POST or GET should be sanitized
before being applied.

~ Anders

On 5/10/07, theju <[EMAIL PROTECTED]> wrote:
>
> The data is sanitized (taken from a form,cleaned and put in hidden
> fields, confirmed by the user and then saved to a model...its just
> that i've not showed all the code) and only then am I posting it to
> the model.
>
> Anyways thanks for the idea on the super __init__ function. Will check
> it up...
>
> Thanks Anders.
>
> -Thejaswi Puthraya
>
>
> >
>

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



Re: Passing Django Model objects between machines

2007-04-17 Thread anders conbere

On 4/17/07, johnny <[EMAIL PROTECTED]> wrote:
>
> Anyone know, how I can pass Model object from one machine that runs
> Django, to another machine that doesn't have Django, but uses
> python?
>
> Thank you.
pickle the object or serialize it to a similarly readable format.

http://docs.python.org/lib/module-pickle.html
http://svn.red-bean.com/bob/simplejson/tags/simplejson-1.3/docs/index.html
http://www.djangoproject.com/documentation/serialization/

~ Anders

>
>
> >
>

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



Re: about newforms

2007-04-09 Thread anders conbere

My experience has been that if you are able to use the newforms
convenience functions (form_for_model and form_for_instance) there is
a sizable amount of information on the net on how to effectively
implement them. However there seems to be almost no body of knowledge
regarding effective use of custom forms.

This is a problem for a couple reasons, most importantly in my
opinion, teaching people how to use forms through the convenience
functions doesn't give any indication as to how forms work in the
backend and behind the scenes.  Which in turn makes it more difficult
to learn about important tools like subclassing field types.

~ Anders

On 4/9/07, Craig Kuhns <[EMAIL PROTECTED]> wrote:
>
> I found this example to help me alot when trying to figure out the newforms.
> http://code.pui.ch/2007/01/07/using-djangos-newforms/
>
> >
>

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



Re: Filtering database results

2007-04-08 Thread anders conbere

indeed you can't do equality operations inside the database api.
You'll want to do something like

story_list.filter(pub_data__gte = datetime.now())

Where __gte indicated greater than

~ Anders

On 4/8/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Hello Anders,
>
> Thank you for your reply.
>
> Like I said this is my first app in Django and I guess this is one of
> those logic things that is best I overcome early ;)
>
> I have tried what I think is your suggestion that is:
>
> story_list.filter(pub_date <= datetime.now())
>
> And django says that global name 'pub_date' is not defined.
>
> Now pub_date is in the story model. I thought it would have been in
> the story_list object because of: story_list =
> tag.story_set.order_by('-pub_date', 'title')
>
> But it's not.
>
> Any ideas what I am doing wrong ?
>
>
> >
>

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



Re: Filtering database results

2007-04-08 Thread anders conbere

On 4/8/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I am writing a blog as my first app in Django. I have got a view that
> works ok, but I need to filter this further so that it brings up all
> stories that have the matching tag, but also were created before
> todays date.
>
> The tags are in a many to many relationship with the stories.
>
> I am unsure of the syntax to do so. Can anyone please help ?

It's important to remember that story_set is just a manager, which
means you treat it just like you would Story.objects.  If you want to
filter that model, all you need to do is use the same filter syntax as
you normally would.

http://www.djangoproject.com/documentation/db-api/#filtering-objects

~ Anders

>
> Thank you
>
>
>
> This is my view:
>
> # Create your views here.
>
> from django.shortcuts import render_to_response
> from django.views.generic.list_detail import object_list
> from mysite.blog.models import Story, Tag
> from django.template import Context, loader
> from django.http import HttpResponse
>
> def stories_by_tag(request, slug):
>
> tag = Tag.objects.get(slug=slug)
> story_list = tag.story_set.order_by('-pub_date', 'title')
>
> t = loader.get_template('blog/stories_by_tag.html')
> c = Context({
> 'object_list': story_list,
> 'tag_name': tag.name,
> })
>
> return HttpResponse(t.render(c))
>
>
> >
>

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



Re: ANN: Upcoming backwards-incompatible changes to Django development version

2007-04-06 Thread anders conbere

At least the auto_now and auto_now_add options are much better handled
by overwriting a models save method

class MyModel(models.Model):
self.created = models.DatetimeField()
self.modified = models.DatetimeField()

def save(self):
if not self.id:
self.created = datetime.datetime.now()
else:
self.modified = datetime.datetime.now()

super(MyModel, self).save()

On 4/6/07, Henrik Lied <[EMAIL PROTECTED]> wrote:
>
> > Examples of some of these changes are:
> >
> > * Removing the "auto_now" and "auto_now_add" options in Django models.
> >
> Is this removed without a substitute?
>
>
> > * Removing the LazyDate shortcut.
> >
> Again, is this removed without a substitute?
>
>
> >
>

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



Re: Adding an error to an empty error list with newforms?

2007-04-04 Thread anders conbere

If you're using custom forms it's often times much easier to do
validation within the forms class using the clean_xxx() methods. I
know this isn't the question you're asking, but I feel like that
should be thrown out there.

~ Anders

On 4/4/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Hey All,
>
> I'm trying to use newforms to create a form to login on my site
> (there's some stuff in the userprofile which prevents me from using
> ths standard django.contrib.auth.views.login view)
>
> I nearly have everything set up just as I'd like it.. but it seems
> that when newforms validators have performed their stuff on my form,
> and found no validation errors of their own, they won't let me add
> anything to the empty list which calling form['fieldname'] will give
> you.
>
> I've tried form['fieldname'].append('whatever') and form['fieldname']
> += ['whatever'] -- both with no avail.
>
> Could someone perhaps explain to me what I could do to work around the
> AttributeError that I get every time I try something like this. For
> the record, I can append to the list when there _are_ validation
> errors. Seems strange to me.
>
> Many Thanks,
> Oliver
>
>
> >
>

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



Re: Using a numeric POST in Newforms to serve a URL (You'd think that this would be easy. )

2007-04-01 Thread anders conbere

On 4/1/07, queezy <[EMAIL PROTECTED]> wrote:
>
> Hi Anders!
>
> Thanks a lot!!  This is exactly what I need.
>
> Sincerely,
>
> -Warren

Glad to help :)

~ Anders

>
> ----- Original Message -
> From: "anders conbere" <[EMAIL PROTECTED]>
> To: <django-users@googlegroups.com>
> Sent: Sunday, April 01, 2007 11:54 AM
> Subject: Re: Using a numeric POST in Newforms to serve a URL (You'd think
> that this would be easy. )
>
>
> >
> > are you just looking for how to access post variables?
> >
> > request.POST is a dictionary that stores the post variables.
> >
> > if you want to access some id you post to the view you just do something
> > like
> >
> > if request.POST:
> >request.POST['id']
> >
> > On 4/1/07, queezy <[EMAIL PROTECTED]> wrote:
> >>
> >> Hi!
> >>
> >> I think (but I could be mistaken) that the article suggested on this is
> >> about going to different URLs.  However, I want to just use newforms and,
> >> based on a simple form, POST a numeric.  Upon arrival at the view (which
> >> is
> >> the SAME view for all form choices) the user is served up a PDF based on
> >> the
> >> numeric sent.  So if the user clicks on the form for a report for Office
> >> 110, a "110" is posted and the user is shown 110.pdf.
> >>
> >> So it is dead simple, but seemingly difficult to accomplish in Django.
> >>
> >> Is there a pretty straightforward way to just POST a numeric and, based
> >> on
> >> that, serve a URL?
> >>
> >> Thanks a lot!
> >>
> >> -Warren
> >>
> >>
> >> >
> >>
> >
> > >
>
>
> >
>

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



Re: Using a numeric POST in Newforms to serve a URL (You'd think that this would be easy. )

2007-04-01 Thread anders conbere

are you just looking for how to access post variables?

request.POST is a dictionary that stores the post variables.

if you want to access some id you post to the view you just do something like

if request.POST:
request.POST['id']

On 4/1/07, queezy <[EMAIL PROTECTED]> wrote:
>
> Hi!
>
> I think (but I could be mistaken) that the article suggested on this is
> about going to different URLs.  However, I want to just use newforms and,
> based on a simple form, POST a numeric.  Upon arrival at the view (which is
> the SAME view for all form choices) the user is served up a PDF based on the
> numeric sent.  So if the user clicks on the form for a report for Office
> 110, a "110" is posted and the user is shown 110.pdf.
>
> So it is dead simple, but seemingly difficult to accomplish in Django.
>
> Is there a pretty straightforward way to just POST a numeric and, based on
> that, serve a URL?
>
> Thanks a lot!
>
> -Warren
>
>
> >
>

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



Re: Problem figuring out generic view with drop down box

2007-04-01 Thread anders conbere

On 4/1/07, queezy <[EMAIL PROTECTED]> wrote:
>
> Hi!
>
> I have this: http://somewebaddress/; method="POST">
> and then this:
>
>
>   Click here to
> choose
>   100 Dummy Entry 1
>   106 Dummy Entry 2
>   107 Dummy Entry 3
> 
>
> So it is a drop-down box with office numbers.  The idea is that it goes to
> urls.py:
>
> from django.views.generic.simple import redirect_to
> urlpatterns = patterns('django.views.generic.simple',
>(r'^$', front),
>(r'^(?P\d+)/$', 'redirect_to', {'url': '/%(id)s.pdf'}),
>)
>
> However this cannot work as it goes to the url and tries to pass the
> variable "office" with a given value.  However, when it goes it ends up at
> the url which has nothing after it (because it isn't a GET but a POST) and
> it uses the url pattern "front" to just display the form again.
>
> So I am not seeing how to pass variables and values via POST within the
> Django framework.   Can someone suggest alternative code above so that this
> would work?

This would probably best be handled by wrapping the redirect_to generic view.

#in views.py
from django.views.generic.simple import redirect_to

def user_lists(request, id):
url = '/%ss.pdf'' % id
return redirect_to(request, url=url)

James Bennet has a nice discussion on how to effectively use this
http://www.b-list.org/weblog/2006/11/16/django-tips-get-most-out-generic-views

~ Anders

>
> Thanks so much!
>
> -Warren
>
>
> >
>

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



Re: IRC

2007-03-19 Thread anders conbere

what happens when you try to join #django

the command would be

/join #django

~ Anders

On 3/19/07, Todd O'Bryan <[EMAIL PROTECTED]> wrote:
>
> I'm trying to use XChat to connect to the IRC channel, but I can only
> find #django-br and #django-fr on FreeNode.
>
> What am I stupidly doing?
>
> Todd
>
>
> >
>

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



Re: Administration features in user pages - newbie

2007-03-12 Thread anders conbere

Gilhad,

just read the documentation.

~ Anders

On 3/12/07, Gilhad <[EMAIL PROTECTED]> wrote:
>
>
>  Is anywhere some simple tutorial, how to implement such features (filters,
> sorting, pagination) into my views? Or is the fastest way try to read and
> understand source of  django/contrib/admin ?
>
>  Thanks for pointing me, where I should continue with study ...
>
> --
> Zdravi
>  Gilhad
>  [EMAIL PROTECTED]
>
> >
>

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



Re: (x)html tags used to render newforms

2007-03-11 Thread anders conbere
You can layout forms in django in which ever way you want. By default
the generic views don't use tables, and newforms has several
convenience functions that will display forms in a number of different
styles (as_p, as_ul). These are all standard html (as well as xhtml)
tags that should be supported by all browsers.

~ Anders

On 3/11/07, Fr�d�ric Roland <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I was discussing about layout of forms using CSS and heard that there
> was some tags such as fieldset, label and legend that should allow us to
> make the layout of forms without tables. Is there a reason these tags
> aren't used to render forms in Django ? Does it is hard to add them ?
> (Something like as_label() for example.)
>
> Are these tags well supported by browsers ?
>
> CC.
>
>
> >
>

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



Re: How to define non-persisted attributes in Model

2007-03-10 Thread anders conbere

well like I said you can either make that particular field not a model
object, or you could just add the attributes at run time.  I'm not
familiar with using the json serializer so I'm not sure about the
specifics there, but for simply adding attributes to the model that
wouldn't be saved to the db, both of those options are viable.

~ Anders

On 3/10/07, Kenny Lee <[EMAIL PROTECTED]> wrote:
> I need a model as i will need to save to the database. Just that i need to
> serialize the object to send it to json, and it will be helpful to have some
> custom attributes for temporary processing, but will not be saved to the db.
>
>
>
> On 3/10/07, anders conbere <[EMAIL PROTECTED]> wrote:
> >
> > I would just not make it a model.* since you don't want that value to
> > be part of the Database, just don't use the ORM for it.
> >
> > ~ Anders
> >
> > On 3/10/07, shevken <[EMAIL PROTECTED]> wrote:
> > >
> > > class Message(models.Model):
> > > description = models.CharField(maxlength=200)
> > > author = models.ForeignKey(User)
> > > temp = models.CharField(maxlength=100)
> > >
> > >
> > > When i syncdb, i do not want the column temp to be created. Is there
> > > any arguments i can pass to enable this?
> > >
> > > Eg.
> > >
> > > temp = models.CharField(maxlength=100, persist=False)
> > >
> > >
> > > >
> > >
> >
> > > >
> >
>

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



Re: How to define non-persisted attributes in Model

2007-03-10 Thread anders conbere

I would just not make it a model.* since you don't want that value to
be part of the Database, just don't use the ORM for it.

~ Anders

On 3/10/07, shevken <[EMAIL PROTECTED]> wrote:
>
> class Message(models.Model):
> description = models.CharField(maxlength=200)
> author = models.ForeignKey(User)
> temp = models.CharField(maxlength=100)
>
>
> When i syncdb, i do not want the column temp to be created. Is there
> any arguments i can pass to enable this?
>
> Eg.
>
> temp = models.CharField(maxlength=100, persist=False)
>
>
> >
>

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



Re: Newforms and custom validators

2007-03-09 Thread anders conbere

You'll be wanting to add clean_ methods to the Form class definition.

check out the forms tests and search for clean_xxx

http://code.djangoproject.com/browser/django/trunk/tests/regressiontests/forms/tests.py

you can see an example of use here:
http://code.google.com/p/django-registration/

~ Anders

On 3/9/07, Andreas Ahlenstorf <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I'm trying to build a form using newforms and I like to attach some
> custom validators to my fields. Unfortunately the docs don't mention
> how I'm supposed to do it. I already looked trought the code, but as
> a Python novice I wasn't able to find some replacement for the old
> validator_list parameter and dealing with a custom clean() method
> doesn't seem very handy to me. Any suggestions?
>
> A.
>
>
> >
>

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



Re: Intializing newforms Form objects

2007-03-08 Thread anders conbere

On 3/8/07, Rubic <[EMAIL PROTECTED]> wrote:
>
> Anders,
>
> I think the simple answer is for foreign keys (including
> ChoiceFields when they're foreign keys), you want
> to pass it the id/pk of the object.  If the ChoiceFields
> are a list of tuples, just pass it the value.
>
> For multiple selection values, pass it a list of the values
> you want selected.  I have an example here where I
> store the value as a comma-delimited string, and use
> a custom widget to convert it to a list:
> http://www.djangosnippets.org/snippets/23/
>

That's pretty slick if I do say so myself.  Thanks, I think what I
really need to do is sit down and make a test model that has, m2m,
o2m, and FK relations, and then build a form and a bunch of tests and
just hammer out exactly what's going on in there.

> --
> Jeff Bauer
> Rubicon, Inc.
>
>
> >
>

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



Re: Intializing newforms Form objects

2007-03-08 Thread anders conbere

On 3/8/07, Vertigo <[EMAIL PROTECTED]> wrote:
>
> I am struggling right now with the same concerns :-)
> I have a hand-written form for a model with ManyToMany field.
>
> So far, I noted a few things that helped me come to a working
> solution, but maybe not really elegant...
>
> The form initialization with an object looks like this (I hope...):
> my_form = MyForm(initial=my_object.__dict__)
> => ManyToMany fields do not show up in that __dict__.
>
> I had to add them by hand, turning the above one-liner into this:
> initial_values = my_object.__dict__
> initial_values.update({'m2m_field' = [obj.id for obj in
> my_object.m2m_field.all()]})
> my_form = MyForm(initial=initial_values)
>
> To summarize, I built the list of ids from the ManyToMany relation to
> my form, appending that list to the dict passed as initial data.
>
> I am not really happy with that solution, maybe some more advanced
> newforms user may lead a better way.

I'm hoping to make a generic function that would do both __dict__ and
handle m2m fields (o2m fields as well) that would let you one off
these kinds of things.  The problem with this stuff being that if you
have an object with any signifigant number of m2m fields there's just
a lot of cruft in your view.

>
>
> >
>

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



Intializing newforms Form objects

2007-03-07 Thread anders conbere

The initial parameter in the newforms Form constructor is a dict that
matches form field names to their respective initial values.  This
makes great sense with simple one to one mappings, however I've been
struggling to find what kind of objects it expects for items such as
manyToMany fields oneToMany fields, ChoiceFields, etc.

Any help would be much appreciated.

Thanks,
Anders

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



Re: newforms - filling a custom form with data from a model instance

2007-03-07 Thread anders conbere

You're actually looking for the "initial" parameter of the form
initialization function.  This is a dict you can pass to the form to
set the "initial" data.

so in your example you would want to pass to the form something like

m = MyModel.objects.get(pk=1)
f = MyForm(initial = {'field1': m.field1, "field2': m.field2,})

supposing you don't have an relations in the model you can simple pass
it the __dict__ attribute of your model instance.

f = MyForm(initial = m.__dict__)

this works pretty well and simply needs to have the ManyToMany and
ForeignKey fields set up individually.  However that's a bit of a pain
to be doing over and over, and if a model has a signifigant number of
relations it's not particularly useful.  What I've been looking at
trying to pull together is a function that converts a model to a dict
that has the relations in forms that the form initialization function
understands.

~ Anders

On 3/6/07, orestis <[EMAIL PROTECTED]> wrote:
>
> Since form_for_model isn't nearly finished yet (regarding with
> FileFields and customization - or I just can't find how it works), I
> have decided to just repeat myself and create my own forms.
>
> I thought that it'd be very intuitive if a form instance gets bound to
> the data from a model instance, but it seems it doesn't. To clarify
> things:
>
> def MyForm(newforms.Form):
>   field1=newforms.CharField()
>   field2=newforms.CharField()
>
>
> def MyModel(models.Model):
>   field1=models.TextField()
>   field2=models.TextField()
>
>
> m = MyModel.objects.get(pk=1)
> f = MyForm(f) # this should pre-populate the form with the data from
> the model, but it doesn't.
> #In fact, nothing even gets displayed on the screen...
>
> Am I assuming something wrong ? I'd love to use form_for_model, but
> I'm using compound models (it's a user profile, really) and it's not
> very useful, as I'll still have to customize it extensively.
>
> Or should I just display more than one form on a page ? Meaning:
>
> def myview(request):
>   form1 = MyForm1(request.POST) # some fields are here
>   form2 = MyForm2(request.POST) # some other fields are here
>   #save the forms.
>
> The user will see just one form, but it'll be split behind the scenes
> to map to different Forms and Models...
>
> Do I make sense ?
>
> Thanks :)
>
>
> >
>

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



Re: Solution: change only a subset of a model's field in newforms

2007-02-28 Thread anders conbere

On 2/28/07, Joseph Kocherhans <[EMAIL PROTECTED]> wrote:
>
> On 2/28/07, akaihola <[EMAIL PROTECTED]> wrote:
> >
> > It must be a common need to allow the user to change only some fields
> > of an object and keep old values for the rest.
> >
> > So far with newforms this has involved copying values explicitly from
> > the database object to the form object. Looking at newforms code I
> > realized that a cleaner way is to just not try to copy missing fields
> > from the form object to the database object before saving.
> >

Similarly from a non-autogenerator standpoint there is currently no
method for taking data in an instance of an object and passing that to
the form for initialization.  The best we could come up with that
using object_instance.__dict__ and then feeding in by hand foreign
fields and manyToMany fields.

Perhaps what we need is really a more abstracted function that would
allow for similar syntax to what was proposed but works independant of
the auto-generator functions.

something like a object_instance.values(include = ('content',))

which could then be utilized by the autogenerators to provide that
same functionality while offering to those of us who don't fit the
auto-gen mold, to be able to have similar functionality.

~ Anders

> > For one possible solution, see 
> > http://akaihola.blogspot.com/2007/02/django-newforms-improvement.html
> > for details and the code.
> >
> > The code is based on newforms.models and makes minimal changes to
> > form_for_instance (and its helper functions) to achieve the new
> > functionality.
> >
> > If this new behaviour doesn't violate the intentions behind newforms,
> > could it be adapted into Django?
>
> I've written similar code, and that functionality definitely belongs
> in Django. The best way to get it considered for inclusion is to file
> a patch with docs and tests. You may want to propose the syntax on
> django-developers first, however.
>
> http://www.djangoproject.com/documentation/contributing/#submitting-patches
>
> Joseph
>
> >
>

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