Re: Creating radio button search app

2009-07-22 Thread Joshua Russo
On Wed, Jul 22, 2009 at 10:39 PM, Joshua Russo wrote:

> On Wed, Jul 22, 2009 at 10:58 AM, Divesh Gidwani wrote:
>
>>
>> Also, what kind of views do I need? I'm really confused about that
>> part.
>
>
> If you want to mimic the current application you will need to create custom
> views and forms. It's really easy once you get the idea, but it's taken me a
> couple of go-a-rounds to get the concepts solidified in my own head. The
> following is an extremely simplified version of a form I have on the home
> page of the app I'm working on.
>
> I'll start from urls.py:
>
> from adminTributaria.matriz import views
> ...
> urlpatterns = patterns('',
> ...
> (r'^$', views.bemvindo)
> )
>
> Next views.py in my app called matriz:
>
> from django import template
> from django.shortcuts import render_to_response
>
> from adminTributaria.matriz.forms import BemvindoForm
>
> def bemvindo(request):
> if request.method == 'POST':
> curForm = BemvindoForm(request.POST)
> if curForm.is_valid():
> # Your form passed validation, do what you want with the data
> here
> # The cleaned_data dictionary will have proper Python objects
> curMatrizID = curForm.cleaned_data['matrizID']
> ...
> else:
> curForm = BemvindoForm()
>
> context = {
> 'title': _('Home'),
> 'form': curForm
> }
>
> return render_to_response('matriz/index.html', context,
> context_instance=template.RequestContext(request))
>
> Now the forms.py in matriz:
>
> from django import forms
>
> class BemvindoForm(MyForm):
> matrizID = forms.IntegerField()
> ...
>
>
> The only thing that I haven't shown here is the template. For my templates,
> I generally take a copy of base.html in
> django\contrib\admin\templates\admin\. I'll modify that how I like and then
> inherit from it. The template inheritance is really slick.
>
> I would recommend reading these sections of the docs:
> http://docs.djangoproject.com/en/dev/topics/http/urls/#topics-http-urls (If
> you are weak in the area of regular expressions, take time to understand
> them here, it makes all the difference)
> http://docs.djangoproject.com/en/dev/topics/http/views/#topics-http-views
> http://docs.djangoproject.com/en/dev/topics/forms/#topics-forms-index
> http://docs.djangoproject.com/en/dev/topics/templates/#topics-templates
>

Sorry, cut and paste error

class BemvindoForm(MyForm):
should be
class BemvindoForm(forms.Form):

I subclassed forms.Form in my app

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



Re: Creating radio button search app

2009-07-22 Thread Joshua Russo
On Wed, Jul 22, 2009 at 10:58 AM, Divesh Gidwani wrote:

>
> Also, what kind of views do I need? I'm really confused about that
> part.


If you want to mimic the current application you will need to create custom
views and forms. It's really easy once you get the idea, but it's taken me a
couple of go-a-rounds to get the concepts solidified in my own head. The
following is an extremely simplified version of a form I have on the home
page of the app I'm working on.

I'll start from urls.py:

from adminTributaria.matriz import views
...
urlpatterns = patterns('',
...
(r'^$', views.bemvindo)
)

Next views.py in my app called matriz:

from django import template
from django.shortcuts import render_to_response

from adminTributaria.matriz.forms import BemvindoForm

def bemvindo(request):
if request.method == 'POST':
curForm = BemvindoForm(request.POST)
if curForm.is_valid():
# Your form passed validation, do what you want with the data
here
# The cleaned_data dictionary will have proper Python objects
curMatrizID = curForm.cleaned_data['matrizID']
...
else:
curForm = BemvindoForm()

context = {
'title': _('Home'),
'form': curForm
}

return render_to_response('matriz/index.html', context,
context_instance=template.RequestContext(request))

Now the forms.py in matriz:

from django import forms

class BemvindoForm(MyForm):
matrizID = forms.IntegerField()
...


The only thing that I haven't shown here is the template. For my templates,
I generally take a copy of base.html in
django\contrib\admin\templates\admin\. I'll modify that how I like and then
inherit from it. The template inheritance is really slick.

I would recommend reading these sections of the docs:
http://docs.djangoproject.com/en/dev/topics/http/urls/#topics-http-urls (If
you are weak in the area of regular expressions, take time to understand
them here, it makes all the difference)
http://docs.djangoproject.com/en/dev/topics/http/views/#topics-http-views
http://docs.djangoproject.com/en/dev/topics/forms/#topics-forms-index
http://docs.djangoproject.com/en/dev/topics/templates/#topics-templates

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



Re: Creating radio button search app

2009-07-22 Thread Divesh Gidwani

Also, what kind of views do I need? I'm really confused about that
part.

If somebody has snippets of their code that they may have written,
it'll be great to see how its done.

Thanks.

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



Creating radio button search app

2009-07-22 Thread Divesh Gidwani

I have this site that I want to design on Django. I have already
created the mysql side of it, and the mysql database is ready. Also,
i
have loaded mysqldb it works too.

This is the site I have to re-design on Django:

http://gomezlab.bme.unc.edu:8080/~kdauria/search.php

so far i have this in my models.py:

class Groups(models.Model):
group_id = models.IntegerField(primary_key=True)
school = models.CharField(max_length=60, db_column='School',
blank=True) # Field name made lowercase.
position = models.CharField(max_length=60, db_column='Position',
blank=True) # Field name made lowercase.
class Meta:
db_table = u'groups'
def __unicode__(self):
return self.position

class Persongroups(models.Model):
pg_id = models.IntegerField(primary_key=True, db_column='pg_ID') #
Field name made lowercase.
person_id = models.IntegerField(null=True, blank=True)
group_id = models.IntegerField(null=True, blank=True)
class Meta:
db_table = u'persongroups'
def __unicode__(self):
return unicode(self.pg_id)

class Persons(models.Model):
person_id = models.IntegerField(primary_key=True)
firstname = models.CharField(max_length=60, db_column='Firstname',
blank=True) # Field name made lowercase.
lastname = models.CharField(max_length=60, db_column='Lastname',
blank=True) # Field name made lowercase.
class Meta:
db_table = u'persons'
def __unicode__(self):
return self.firstname


How can I get those radio button like search fields? How to bring up
the search?

Any suggestions, or resources would be helpful.

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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---