Re: models and forms

2019-04-29 Thread Nelson Varela
What do you have so far. show some code or explain what you have so far

On Monday, April 22, 2019 at 1:40:06 PM UTC+2, Shereyne Casimsiman wrote:
>
> I am current making a project and django is very new to me, I've been 
> following tutorials but it did not answer my concern..
> My project is to build a quiz that will have an audio as the question . I 
> already installed  the django-audiofield and successfully added it into the 
> admin but my problem is that I don't know how to show it in the templates 
> please help me ... I am running out of time  
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c126f0ba-21c3-4123-9a43-37fd92121bd9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


models and forms

2019-04-22 Thread Shereyne Casimsiman
I am current making a project and django is very new to me, I've been 
following tutorials but it did not answer my concern..
My project is to build a quiz that will have an audio as the question . I 
already installed  the django-audiofield and successfully added it into the 
admin but my problem is that I don't know how to show it in the templates 
please help me ... I am running out of time  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7bde61fb-7479-4c7a-a9a4-b8c88f06f6e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to clean a model after the related models inline forms have been saved?

2018-08-26 Thread Andy
Please forget about the persisting data part. 
The problem is that inside the parent form i dont have access to the 
related data and the formsets new related data is validated after the 
parent models data.
Inside the formset every related data model does not have access to the 
other related instances.

I want to have additional validation after all data on the admin page has 
been processed .. not necessarily saved into the database, but i need some 
way of doing additional validation after the basic stuff has been taken 
care of by the admin and its form.



Am Sonntag, 26. August 2018 18:44:17 UTC+2 schrieb Jason:
>
> I still don't understand why you want to persist unvalidated data to the 
> db then?  if a user requests the data in mid-update, that's something that 
> can be handled with transaction locks on the db.  so when that happens, the 
> request will wait till the locks are released before executing the db query
>
>
> https://stackoverflow.com/questions/42520917/does-django-atomic-transaction-lock-the-database
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6aa2f0c1-eb89-46fa-8b19-6d4a6927405b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to clean a model after the related models inline forms have been saved?

2018-08-26 Thread Jason
I still don't understand why you want to persist unvalidated data to the db 
then?  if a user requests the data in mid-update, that's something that can 
be handled with transaction locks on the db.  so when that happens, the 
request will wait till the locks are released before executing the db query

https://stackoverflow.com/questions/42520917/does-django-atomic-transaction-lock-the-database

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d4044b1c-9ef8-4b17-99e3-67c8ea1d82ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to clean a model after the related models inline forms have been saved?

2018-08-26 Thread Andy


Am Sonntag, 26. August 2018 18:29:49 UTC+2 schrieb Jason:
>
> I think we're missing a few things.  how fast does this query with updated 
> values execute after the form submits? 
>

a neglectable amount of milliseconds
 

> if you need to return the value back to the view, can't you do some sort 
> of post-save retrieval and form populate?
>

No i dont want to return anything but a possible validation error based on 
all related objects new data. 
I probably see myself rewriting the changeform_view and manually adding the 
error the the forms non field errors, unless somebody comes up with a more 
clever idea.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1d2f8a9e-57f3-4d67-83b7-6f6f6a0cf9ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to clean a model after the related models inline forms have been saved?

2018-08-26 Thread Jason
I think we're missing a few things.  how fast does this query with updated 
values execute after the form submits? if you need to return the value back 
to the view, can't you do some sort of post-save retrieval and form 
populate?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f7dc3c9f-3630-4ec8-96f0-ce28c14d7d29%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to clean a model after the related models inline forms have been saved?

2018-08-26 Thread Andy


Am Sonntag, 26. August 2018 18:07:25 UTC+2 schrieb Jason:
>
> why would you want to persist unvalidated data to your db?
>
>>
>>
Well, i dont necessarily have to, but i somehow need to be able to perform 
a query with all updated data taken into account. The easiest solution i 
came up with is putting everything into the DB while in transaction so i 
could perform my queries and rollback if the checks dont work out. 

Im open to any other ideas.
And is there a prepared admin function that is suitable for validation 
logic after related objects are validated?
I might also just write some validation data to the parent while executing 
the formet validation and so i could verify my parent validation against 
this extra data even without additional queries against the DB.

So far i just see that the changeform_view handles object and formset 
validation without any way of interfering (other than rewriting that view 
logic).

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2f46c2d4-a628-4571-8f23-9607125d462b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to clean a model after the related models inline forms have been saved?

2018-08-26 Thread Jason
why would you want to persist unvalidated data to your db?

On Sunday, August 26, 2018 at 10:42:28 AM UTC-4, Andy wrote:
>
> I want to execute a check after the related data from the admin has been 
> saved, but the default clean methods get executed before the formsets are 
> saved. Where could i place my check to have access to a full version of 
> what has been changed on the admin page?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/02d9d1ae-9f17-4c16-8af6-88911f461442%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to clean a model after the related models inline forms have been saved?

2018-08-26 Thread Andy
I want to execute a check after the related data from the admin has been 
saved, but the default clean methods get executed before the formsets are 
saved. Where could i place my check to have access to a full version of 
what has been changed on the admin page?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0623c315-eed4-407a-9166-7fc66910adeb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to manage range of hours in models and forms in django1.4

2012-06-29 Thread Nikhil Verma
Thanks for the help guys.

On Fri, Jun 29, 2012 at 11:37 AM, Sunny Nanda <snand...@gmail.com> wrote:

> One way to store such information can be like this:
> Create a model "Day". This will hold entries for each day i.e. from Monday
> till Sunday
> In the UserProfile model, create a ManyToMany relation to the above
> defined Day model through an intermediate table (say WorkingHours) which
> can hold the "from" and "to" time.
>
> Partial example below:
>
> class UserProfile(models.Model):
>> working_hours = models.ManyToManyField("Day", through="WorkingHours")
>>
>> class WorkingHours(models.Model)
>> profile = models.ForeignKey("UserProfile")
>> day = models.ForeignKey("Day")
>> from_time = models.**TimeField()
>> to_time = models.**TimeField()
>>
>
> While creating the forms, take input from the user for the WorkingHours
> model. This way, the days of work will not be hardcoded, and user can
> select mutiple choices.
>
> Regards,
> Sandeep
>
>
>
> On Friday, June 29, 2012 10:16:47 AM UTC+5:30, Nikhil Verma wrote:
>>
>>
>> Hi
>>
>> I am developing an event app which has users who publish events , other
>> users also.
>> Now users have their profile info for which i have made a very common
>> UserProfile Model with all the necessary details in it.
>>
>> I have a requirement where in UserProfile model i need to display a field
>> institue_hours_of_operation( no. of hours that an institute works)
>>
>>
>> class UserProfile(models.Model):
>> user = models.ForeignKey(User, blank=True, null=True, unique=True)
>> first_name = models.CharField(max_length=**30, blank=True)
>> last_name = models.CharField(max_length=**30, blank=True)
>> gender = models.CharField(max_length=1, choices=GENDER_CHOICES,
>> blank=True)
>> birth_date = models.DateField(auto_now_add=**True)
>> street_address = models.CharField(max_length=**75, blank=True)
>> city = models.CharField(max_length=**30, blank=True)
>> zip_code = models.IntegerField(max_**length=7, blank=True, null=True)
>> country = models.CharField(max_length=**30, blank=True)
>> mobile = models.CharField(max_length=**15, blank=True)
>> home_phone = models.CharField(max_length=**15, blank=True)
>> primary_email = models.EmailField(max_length=**60, blank=True)
>> secondary_email = models.EmailField(max_length=**60, blank=True)
>> institution_name = models.CharField(max_length=**
>> 100,blank=True,null=True)
>> institution_website = models.CharField(max_length=**
>> 100,blank=True,null=True)
>>
>>
>> # Field to be added
>>
>> It will be displayed in html like this
>>
>> Insitutue hour of operation :   Monday  9.00 - 17.00 (Monday will be
>> hardcoded,Time will be filled by user)
>>   **Tuesday 9.00 - 17.00
>> (Monday will be hardcoded,Time will be filled by user)
>>
>>   ** and so on
>>
>> # Note the weekdays like monday,  tuesday they are all hardcoded as
>> requirement but i don't want that to be hardcoded.
>> Also i am using a django forms  to display this.
>>
>>
>> How can i design this form field as well in models or What should be the
>> type of this field both in models and forms such that weekdays remain
>> dynamic(i can simply generate them from loop) and the user can fill the
>> time  and when he hits submit it will get saved.
>>
>>
>> Thanks in advance.
>>
>>
>>
>> --
>> Regards
>> Nikhil Verma
>> +91-958-273-3156
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/N2ArPbWtQmYJ.
>
> 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.
>



-- 
Regards
Nikhil Verma
+91-958-273-3156

-- 
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: how to manage range of hours in models and forms in django1.4

2012-06-29 Thread Sunny Nanda
One way to store such information can be like this:
Create a model "Day". This will hold entries for each day i.e. from Monday 
till Sunday
In the UserProfile model, create a ManyToMany relation to the above defined 
Day model through an intermediate table (say WorkingHours) which can hold 
the "from" and "to" time.

Partial example below:

class UserProfile(models.Model):
> working_hours = models.ManyToManyField("Day", through="WorkingHours")
>
> class WorkingHours(models.Model)
> profile = models.ForeignKey("UserProfile")
> day = models.ForeignKey("Day")
> from_time = models.**TimeField()
> to_time = models.**TimeField()
>

While creating the forms, take input from the user for the WorkingHours 
model. This way, the days of work will not be hardcoded, and user can 
select mutiple choices.

Regards,
Sandeep


On Friday, June 29, 2012 10:16:47 AM UTC+5:30, Nikhil Verma wrote:
>
>
> Hi
>
> I am developing an event app which has users who publish events , other 
> users also.
> Now users have their profile info for which i have made a very common 
> UserProfile Model with all the necessary details in it.
>
> I have a requirement where in UserProfile model i need to display a field 
> institue_hours_of_operation( no. of hours that an institute works)
>
>
> class UserProfile(models.Model):
> user = models.ForeignKey(User, blank=True, null=True, unique=True)
> first_name = models.CharField(max_length=30, blank=True)
> last_name = models.CharField(max_length=30, blank=True)
> gender = models.CharField(max_length=1, choices=GENDER_CHOICES, 
> blank=True)
> birth_date = models.DateField(auto_now_add=True)
> street_address = models.CharField(max_length=75, blank=True)
> city = models.CharField(max_length=30, blank=True)
> zip_code = models.IntegerField(max_length=7, blank=True, null=True)
> country = models.CharField(max_length=30, blank=True)
> mobile = models.CharField(max_length=15, blank=True)
> home_phone = models.CharField(max_length=15, blank=True)
> primary_email = models.EmailField(max_length=60, blank=True)
> secondary_email = models.EmailField(max_length=60, blank=True)
> institution_name = 
> models.CharField(max_length=100,blank=True,null=True)
> institution_website = 
> models.CharField(max_length=100,blank=True,null=True)
>
>
> # Field to be added
>
> It will be displayed in html like this
>
> Insitutue hour of operation :   Monday  9.00 - 17.00 (Monday will be 
> hardcoded,Time will be filled by user)
>   Tuesday 9.00 - 17.00 
> (Monday will be hardcoded,Time will be filled by user)
>
>and so on
>
> # Note the weekdays like monday,  tuesday they are all hardcoded as 
> requirement but i don't want that to be hardcoded. 
> Also i am using a django forms  to display this.
>
>
> How can i design this form field as well in models or What should be the 
> type of this field both in models and forms such that weekdays remain 
> dynamic(i can simply generate them from loop) and the user can fill the 
> time  and when he hits submit it will get saved.
>
>
> Thanks in advance.
>
>
>
> -- 
> Regards
> Nikhil Verma
> +91-958-273-3156
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/N2ArPbWtQmYJ.
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: how to manage range of hours in models and forms in django1.4

2012-06-29 Thread jonas

Nikhil Verma wrote:


How can i design this form field as well in models or What should be
the type of this field both in models and forms such that weekdays
remain dynamic(i can simply generate them from loop) and the user can
fill the time  and when he hits submit it will get saved.



I would create an extra Model which defines these opening times:

class OpeningTimes(models.Model):
day = models.CharField(max_length=10)
start = models.DateTimeField()
end = models.DateTimeField()

and define a manytomany relation ship from the UserProfile to your 
OpeningTimes model.


I've opted for the DateTimeField here, there's no Time Field in django 
by default. But you could just use any date (maybe use some kind of 
default date or use the current date)
and make sure the time has been filled in correctly. And then just 
extract the right hour from the DateTime field.


Regards,

Jonas;

--
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: how to manage range of hours in models and forms in django1.4

2012-06-29 Thread Melvyn Sopacua
On 29-6-2012 11:01, Nikhil Verma wrote:

> Yes it is the count of the hours.They will enter in the following manner "-
> 
> Monday : 0900-1800, Tuesday and so on ... This will be entered by the user
> who is filling the form.
> 
> Now the text Moday(weekdays can be hardcoded but i personally don't want.)

Untested, but I'd try this:
class DaysOfWeek(models.Model) :
name = models.CharField(max_length=32)

class BusinessHours(models.Model) :
day = models.ForeignKey(DaysOfWeek)
start = models.TimeField()
end = models.TimeField()

class Institute(models.Model) :
   # ...
   business_hours = models.ManyToManyField(BusinessHours)

Not sure if the Admin handles this ok though. An alternative:
class DaysOfWeek(models.Model) :
name = models.CharField(max_length=32)

def __iter__(self) :
return self

def next(self) :
for entry in DaysOfWeek.objects.all() :
 return (entry.id, entry.name)

class BusinessHours(models.Model) :
day = models.CharField(max_length=32, choices=DaysOfWeek)
start = models.TimeField()
end = models.TimeField()

-- 
Melvyn Sopacua


-- 
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: how to manage range of hours in models and forms in django1.4

2012-06-29 Thread Jon Black
If the days have to be hardcoded (I imagine you have a row/field
for each day), then you could use a hardcoded string for the day
(not editable nor related to your model), and provide two Time
fields. Using Time gives you advantages:

* You can use python's DateTime module to calculate the hours
* You can more easily use a funky date/time style widget if you
ever need it
* You will avoid making mistakes trying to calculate the hours
manually
* You can validate the form data using python's date/time module

If you're really open to suggestions (just thinking outside the
box, and possible outside of the scope), but you could use a
separate table to record all hours recorded rather than just
counting the hours as they're entered.

--
Jon Black
www.jonblack.org


On Fri, Jun 29, 2012, at 14:31, Nikhil Verma wrote:

  Hi Jon
  Yes it is the count of the hours.They will enter in the
  following manner "-
  Monday : 0900-1800, Tuesday and so on ... This will be entered
  by the user who is filling the form.
  Now the text Moday(weekdays can be hardcoded but i personally
  don't want.)
  Now if you see this is a simple CharField where the user
  enters details for the number_of_hours.
  So i want to know what type of model field should i create
  CharField or Time Field.
  If i   go for CharField it will simply save the details like
  0900-1800. So if i need to know how many hours that particular
  person is available for work then how will subtract that from
  CharField.
  So i need help to know what exactly the field i should create
  such that it satisfies the template look and backened queries
  also.

On Fri, Jun 29, 2012 at 2:18 PM, Jon Black <[1]jon_bl...@mm.st>
wrote:

I understand that institue_hours_of_operation is a count of the
hours the user has worked, is that correct? If so, I suppose you
just need to count the hours with each form submition and add
that to the current institue_hours_of_operation value. You can do
that logic in a few places. In class-based views, I tend to put
it in form_valid().

Apologies if I've misunderstood :)

--
Jon Black
[2]www.jonblack.org


On Fri, Jun 29, 2012, at 10:16, Nikhil Verma wrote:

Hi
I am developing an event app which has users who publish events ,
other users also.
Now users have their profile info for which i have made a very
common UserProfile Model with all the necessary details in it.
I have a requirement where in UserProfile model i need to display
a field institue_hours_of_operation( no. of hours that an
institute works)
class UserProfile(models.Model):
user = models.ForeignKey(User, blank=True, null=True,
unique=True)
first_name = models.CharField(max_length=30, blank=True)
last_name = models.CharField(max_length=30, blank=True)
gender = models.CharField(max_length=1,
choices=GENDER_CHOICES, blank=True)
birth_date = models.DateField(auto_now_add=True)
street_address = models.CharField(max_length=75, blank=True)
city = models.CharField(max_length=30, blank=True)
zip_code = models.IntegerField(max_length=7, blank=True,
null=True)
country = models.CharField(max_length=30, blank=True)
mobile = models.CharField(max_length=15, blank=True)
home_phone = models.CharField(max_length=15, blank=True)
primary_email = models.EmailField(max_length=60, blank=True)
secondary_email = models.EmailField(max_length=60,
blank=True)
institution_name =
models.CharField(max_length=100,blank=True,null=True)
institution_website =
models.CharField(max_length=100,blank=True,null=True)
# Field to be added
It will be displayed in html like this
Insitutue hour of operation :   Monday  9.00 - 17.00 (Monday
will be hardcoded,Time will be filled by user)
  Tuesday 9.00 -
17.00 (Monday will be hardcoded,Time will be filled by user)
   and so on
# Note the weekdays like monday,  tuesday they are all hardcoded
as requirement but i don't want that to be hardcoded.
Also i am using a django forms  to display this.
How can i design this form field as well in models or What should
be the type of this field both in models and forms such that
weekdays remain dynamic(i can simply generate them from loop) and
the user can fill the time  and when he hits submit it will get
saved.
Thanks in advance.
--
Regards
Nikhil Verma
+91-958-273-3156


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



  --
  You received this message because you are subscribed to the
  Google Groups "Django users" group.
  To post to this group, send email to
  [6]django-users@googlegroups.com.
  To unsubscribe from this group, 

Re: how to manage range of hours in models and forms in django1.4

2012-06-29 Thread Nikhil Verma
Hi Jon

Yes it is the count of the hours.They will enter in the following manner "-

Monday : 0900-1800, Tuesday and so on ... This will be entered by the user
who is filling the form.

Now the text Moday(weekdays can be hardcoded but i personally don't want.)
Now if you see this is a simple CharField where the user enters details for
the number_of_hours.
So i want to know what type of model field should i create CharField or
Time Field.

If i   go for CharField it will simply save the details like 0900-1800. So
if i need to know how many hours that particular person is available for
work then how will subtract that from CharField.

So i need help to know what exactly the field i should create such that it
satisfies the template look and backened queries also.



On Fri, Jun 29, 2012 at 2:18 PM, Jon Black <jon_bl...@mm.st> wrote:

>  I understand that institue_hours_of_operation is a count of the hours the
> user has worked, is that correct? If so, I suppose you just need to count
> the hours with each form submition and add that to the current
> institue_hours_of_operation value. You can do that logic in a few places.
> In class-based views, I tend to put it in form_valid().
>
>  Apologies if I've misunderstood :)
>
>  --
>  Jon Black
>  www.jonblack.org
>
>
>  On Fri, Jun 29, 2012, at 10:16, Nikhil Verma wrote:
>
>
>  Hi
>
> I am developing an event app which has users who publish events , other
> users also.
> Now users have their profile info for which i have made a very common
> UserProfile Model with all the necessary details in it.
>
> I have a requirement where in UserProfile model i need to display a field
> institue_hours_of_operation( no. of hours that an institute works)
>
>
> class UserProfile(models.Model):
> user = models.ForeignKey(User, blank=True, null=True, unique=True)
> first_name = models.CharField(max_length=30, blank=True)
> last_name = models.CharField(max_length=30, blank=True)
> gender = models.CharField(max_length=1, choices=GENDER_CHOICES,
> blank=True)
> birth_date = models.DateField(auto_now_add=True)
> street_address = models.CharField(max_length=75, blank=True)
> city = models.CharField(max_length=30, blank=True)
> zip_code = models.IntegerField(max_length=7, blank=True, null=True)
> country = models.CharField(max_length=30, blank=True)
> mobile = models.CharField(max_length=15, blank=True)
> home_phone = models.CharField(max_length=15, blank=True)
> primary_email = models.EmailField(max_length=60, blank=True)
> secondary_email = models.EmailField(max_length=60, blank=True)
> institution_name =
> models.CharField(max_length=100,blank=True,null=True)
> institution_website =
> models.CharField(max_length=100,blank=True,null=True)
>
>
> # Field to be added
>
> It will be displayed in html like this
>
> Insitutue hour of operation :   Monday  9.00 - 17.00 (Monday will be
> hardcoded,Time will be filled by user)
>   Tuesday 9.00 - 17.00
> (Monday will be hardcoded,Time will be filled by user)
>
>and so on
>
> # Note the weekdays like monday,  tuesday they are all hardcoded as
> requirement but i don't want that to be hardcoded.
> Also i am using a django forms  to display this.
>
>
> How can i design this form field as well in models or What should be the
> type of this field both in models and forms such that weekdays remain
> dynamic(i can simply generate them from loop) and the user can fill the
> time  and when he hits submit it will get saved.
>
>
> Thanks in advance.
>
>
>
> --
> Regards
> Nikhil Verma
> +91-958-273-3156
>
>
> --
> 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.
>
>
>
> --
> 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.
>



-- 
Regards
Nikhil Verma
+91-958-273-3156

-- 
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: how to manage range of hours in models and forms in django1.4

2012-06-29 Thread Jon Black
I understand that institue_hours_of_operation is a count of the
hours the user has worked, is that correct? If so, I suppose you
just need to count the hours with each form submition and add
that to the current institue_hours_of_operation value. You can do
that logic in a few places. In class-based views, I tend to put
it in form_valid().

Apologies if I've misunderstood :)

--
Jon Black
www.jonblack.org


On Fri, Jun 29, 2012, at 10:16, Nikhil Verma wrote:

Hi
I am developing an event app which has users who publish events ,
other users also.
Now users have their profile info for which i have made a very
common UserProfile Model with all the necessary details in it.
I have a requirement where in UserProfile model i need to display
a field institue_hours_of_operation( no. of hours that an
institute works)
class UserProfile(models.Model):
user = models.ForeignKey(User, blank=True, null=True,
unique=True)
first_name = models.CharField(max_length=30, blank=True)
last_name = models.CharField(max_length=30, blank=True)
gender = models.CharField(max_length=1,
choices=GENDER_CHOICES, blank=True)
birth_date = models.DateField(auto_now_add=True)
street_address = models.CharField(max_length=75, blank=True)
city = models.CharField(max_length=30, blank=True)
zip_code = models.IntegerField(max_length=7, blank=True,
null=True)
country = models.CharField(max_length=30, blank=True)
mobile = models.CharField(max_length=15, blank=True)
home_phone = models.CharField(max_length=15, blank=True)
primary_email = models.EmailField(max_length=60, blank=True)
secondary_email = models.EmailField(max_length=60,
blank=True)
institution_name =
models.CharField(max_length=100,blank=True,null=True)
institution_website =
models.CharField(max_length=100,blank=True,null=True)
# Field to be added
It will be displayed in html like this
Insitutue hour of operation :   Monday  9.00 - 17.00 (Monday
will be hardcoded,Time will be filled by user)
  Tuesday 9.00 -
17.00 (Monday will be hardcoded,Time will be filled by user)
   and so on
# Note the weekdays like monday,  tuesday they are all hardcoded
as requirement but i don't want that to be hardcoded.
Also i am using a django forms  to display this.
How can i design this form field as well in models or What should
be the type of this field both in models and forms such that
weekdays remain dynamic(i can simply generate them from loop) and
the user can fill the time  and when he hits submit it will get
saved.
Thanks in advance.

  --
  Regards
  Nikhil Verma
  +91-958-273-3156


  --
  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.

-- 
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.



how to manage range of hours in models and forms in django1.4

2012-06-28 Thread Nikhil Verma
Hi

I am developing an event app which has users who publish events , other
users also.
Now users have their profile info for which i have made a very common
UserProfile Model with all the necessary details in it.

I have a requirement where in UserProfile model i need to display a field
institue_hours_of_operation( no. of hours that an institute works)


class UserProfile(models.Model):
user = models.ForeignKey(User, blank=True, null=True, unique=True)
first_name = models.CharField(max_length=30, blank=True)
last_name = models.CharField(max_length=30, blank=True)
gender = models.CharField(max_length=1, choices=GENDER_CHOICES,
blank=True)
birth_date = models.DateField(auto_now_add=True)
street_address = models.CharField(max_length=75, blank=True)
city = models.CharField(max_length=30, blank=True)
zip_code = models.IntegerField(max_length=7, blank=True, null=True)
country = models.CharField(max_length=30, blank=True)
mobile = models.CharField(max_length=15, blank=True)
home_phone = models.CharField(max_length=15, blank=True)
primary_email = models.EmailField(max_length=60, blank=True)
secondary_email = models.EmailField(max_length=60, blank=True)
institution_name = models.CharField(max_length=100,blank=True,null=True)
institution_website =
models.CharField(max_length=100,blank=True,null=True)


# Field to be added

It will be displayed in html like this

Insitutue hour of operation :   Monday  9.00 - 17.00 (Monday will be
hardcoded,Time will be filled by user)
  Tuesday 9.00 - 17.00 (Monday
will be hardcoded,Time will be filled by user)

   and so on

# Note the weekdays like monday,  tuesday they are all hardcoded as
requirement but i don't want that to be hardcoded.
Also i am using a django forms  to display this.


How can i design this form field as well in models or What should be the
type of this field both in models and forms such that weekdays remain
dynamic(i can simply generate them from loop) and the user can fill the
time  and when he hits submit it will get saved.


Thanks in advance.



-- 
Regards
Nikhil Verma
+91-958-273-3156

-- 
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: Two views, Two models, Two forms, one template

2009-06-16 Thread Jonathan

Nevermind, I was missing something terribly basic and just needed to
stop looking at it for a bit to realize how to combine it.


On May 22, 5:08 pm, Jonathan  wrote:
> I am sure this is some very easy and simple concept I am just not
> grasping.  I have two views which are very similar.  Both take the
> same variable and iterate the applicable data.  I am trying to get
> them to render on the same template.  However, when I create one as a
> template tag and try to pass the common variable, I get variable is
> not defined errors.
>
> def projectfilesindex(request, object_id):
>         def store()
>             ...
>         files = ProjectFileUrl.objects.filter
> (project_number=object_id).order_by('-uploaded')
>         if not request.method == "POST":
>                 form = UploadForm()
>                 return render_to_response(
>                         'projects/files.html',
>                         {"form": form, "files": files},
>                         context_instance = RequestContext(request, object_id)
>                 )
>
>         form = UploadForm(request.POST, request.FILES)
>         if not form.is_valid():
>                 return render_to_response(
>                         'projects/files.html',
>                         {"form": form, "files": files},
>                         context_instance = RequestContext(request, object_id)
>                 )
>
>         file = request.FILES["file"]
>         filename = file.name
>         content = file.read()
>         store(...)
>         p = Project.objects.get(pk=object_id)
>         f = ProjectFileUrl(url="http://someurl.com/; + object_id + "_" +
> filename,
>                 name=object_id + "_" + filename, project_number=p)
>         f.save()
>         files = ProjectFileUrl.objects.filter
> (project_number=object_id).order_by('-uploaded')
>         return render_to_response(
>                 'projects/files.html',
>                 {"form": form, "files": files},
>                 context_instance = RequestContext(request, object_id)
>         )
>
> def announce(request, object_id):
>         announcements = ProjectAnnouncement.objects.filter
> (project=object_id).order_by('-date_posted')
>         if not request.method == "POST":
>                 form = ProjectAnnouncementForm()
>                 return render_to_response(
>                         'projects/announcement.html',
>                         {"form": form, "announcements": announcements},
>                         context_instance = RequestContext(request)
>                 )
>         form = ProjectAnnouncementForm(request.POST)
>         if not form.is_valid():
>                 return render_to_response(
>                         'projects/files.html',
>                         {"form": form, "announcements": announcements},
>                         context_instance = RequestContext(request)
>                 )
>         title = request.POST['title']
>         body = request.POST['body']
>         d = datetime.now()
>         p = Project.objects.get(pk=object_id)
>         a = ProjectAnnouncement(author_user=request.user, date_posted=d,
> project=p, title=title, body=body)
>         a.save()
>         announcements = ProjectAnnouncement.objects.filter
> (project=object_id).order_by('-date_posted')
>         return render_to_response(
>                 'projects/announcement.html',
>                 {"form": form, "announcements": announcements},
>                 context_instance = RequestContext(request)
>         )
>
> As they both stand, they work separately.  Every time I try and
> combine them, or make one a template tag, I end up with an error, or
> only getting one to work and the other fails silently.  When I try and
> make one into a template tag, I end up with the "object_id" is not
> globally defined error.
>
> I'm sure I am missing something really basic.  Does anyone have a
> pointer to get me going in the right direction?
>
> Jonathan
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Two views, Two models, Two forms, one template

2009-05-22 Thread Jonathan

I am sure this is some very easy and simple concept I am just not
grasping.  I have two views which are very similar.  Both take the
same variable and iterate the applicable data.  I am trying to get
them to render on the same template.  However, when I create one as a
template tag and try to pass the common variable, I get variable is
not defined errors.

def projectfilesindex(request, object_id):
def store()
...
files = ProjectFileUrl.objects.filter
(project_number=object_id).order_by('-uploaded')
if not request.method == "POST":
form = UploadForm()
return render_to_response(
'projects/files.html',
{"form": form, "files": files},
context_instance = RequestContext(request, object_id)
)

form = UploadForm(request.POST, request.FILES)
if not form.is_valid():
return render_to_response(
'projects/files.html',
{"form": form, "files": files},
context_instance = RequestContext(request, object_id)
)

file = request.FILES["file"]
filename = file.name
content = file.read()
store(...)
p = Project.objects.get(pk=object_id)
f = ProjectFileUrl(url="http://someurl.com/; + object_id + "_" +
filename,
name=object_id + "_" + filename, project_number=p)
f.save()
files = ProjectFileUrl.objects.filter
(project_number=object_id).order_by('-uploaded')
return render_to_response(
'projects/files.html',
{"form": form, "files": files},
context_instance = RequestContext(request, object_id)
)

def announce(request, object_id):
announcements = ProjectAnnouncement.objects.filter
(project=object_id).order_by('-date_posted')
if not request.method == "POST":
form = ProjectAnnouncementForm()
return render_to_response(
'projects/announcement.html',
{"form": form, "announcements": announcements},
context_instance = RequestContext(request)
)
form = ProjectAnnouncementForm(request.POST)
if not form.is_valid():
return render_to_response(
'projects/files.html',
{"form": form, "announcements": announcements},
context_instance = RequestContext(request)
)
title = request.POST['title']
body = request.POST['body']
d = datetime.now()
p = Project.objects.get(pk=object_id)
a = ProjectAnnouncement(author_user=request.user, date_posted=d,
project=p, title=title, body=body)
a.save()
announcements = ProjectAnnouncement.objects.filter
(project=object_id).order_by('-date_posted')
return render_to_response(
'projects/announcement.html',
{"form": form, "announcements": announcements},
context_instance = RequestContext(request)
)


As they both stand, they work separately.  Every time I try and
combine them, or make one a template tag, I end up with an error, or
only getting one to work and the other fails silently.  When I try and
make one into a template tag, I end up with the "object_id" is not
globally defined error.

I'm sure I am missing something really basic.  Does anyone have a
pointer to get me going in the right direction?

Jonathan

--~--~-~--~~~---~--~~
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: Trying to reuse models and forms

2007-12-12 Thread Kirk Strauser
On Wednesday 12 December 2007, l5x wrote:
> form_for_instance? Check:
> http://www.djangoproject.com/documentation/newforms/#generating-forms-for
>-models

That's only in the SVN version, but if we have to move from .96 to SVN to 
get it then so be it.
-- 
Kirk Strauser


signature.asc
Description: This is a digitally signed message part.


Re: Trying to reuse models and forms

2007-12-12 Thread l5x

form_for_instance? Check: 
http://www.djangoproject.com/documentation/newforms/#generating-forms-for-models
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---