Re: Same form saving to related models

2017-06-09 Thread Elorm Koku
No luck for me?

On Jun 9, 2017 4:43 AM, "Elorm Koku"  wrote:

> Hi guys,
> I need a means to save these 2 models related by FK but I want to use one
> form. I searched but I jus can't do it.
>
> class Student(models.Model):
> ...
>
> class Parent(models.Model):
> 
> child = models.ForeignKey(Student)
>
>
> All I need is a form I can use to every student and their parent
> simultaneously.
> Am I doing this wrong? If so kindly correct me.
> Thanks
>

-- 
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/CAG%2BabP_CYoYx0sqGz0ANKe8H_MFCL03t3WkJmxKvwQa3Wc_0rA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Problems with migrations cleaning up a date field

2017-06-09 Thread Lee Hinde
I'm having problems with a migration after cleaning up an oddity with a
date field and I'm not sure how to fix it.  Any advice appreciated.

I made this change to a date field:

-start_date = models.DateField(db_index=True, default=False,
-  help_text="The date enrollment can begin
this Season.")
+start_date = models.DateField(db_index=True, help_text="The date
enrollment can begin this Season.")

I'm not sure how a default of False ever made it, but I ran across it and
fixed it.

This is the migration that was created:

class Migration(migrations.Migration):

dependencies = [
('district', '0012_auto_20160622_1741'),
]

operations = [
migrations.AlterField(
model_name='season',
name='start_date',
field=models.DateField(help_text=b'The date enrollment can
begin this Season.', db_index=True),
),
]

This is the error I get trying to run the migration:

  Applying district.0013_auto_20170204_1811...Traceback (most recent call
last):
  File "manage.py", line 9, in 
execute_from_command_line(sys.argv)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/core/management/__init__.py",
line 354, in execute_from_command_line
utility.execute()
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/core/management/__init__.py",
line 346, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/core/management/base.py",
line 394, in run_from_argv
self.execute(*args, **cmd_options)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/core/management/base.py",
line 445, in execute
output = self.handle(*args, **options)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/core/management/commands/migrate.py",
line 222, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/db/migrations/executor.py",
line 110, in migrate
self.apply_migration(states[migration], migration, fake=fake,
fake_initial=fake_initial)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/db/migrations/executor.py",
line 148, in apply_migration
state = migration.apply(state, schema_editor)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/db/migrations/migration.py",
line 115, in apply
operation.database_forwards(self.app_label, schema_editor, old_state,
project_state)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/db/migrations/operations/fields.py",
line 201, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/db/backends/base/schema.py",
line 484, in alter_field
old_db_params, new_db_params, strict)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/db/backends/base/schema.py",
line 566, in _alter_field
old_default = self.effective_default(old_field)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/db/backends/base/schema.py",
line 211, in effective_default
default = field.get_db_prep_save(default, self.connection)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/db/models/fields/__init__.py",
line 710, in get_db_prep_save
prepared=False)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/db/models/fields/__init__.py",
line 1322, in get_db_prep_value
value = self.get_prep_value(value)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/db/models/fields/__init__.py",
line 1317, in get_prep_value
return self.to_python(value)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/db/models/fields/__init__.py",
line 1274, in to_python
parsed = parse_date(value)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/utils/dateparse.py",
line 60, in parse_date
match = date_re.match(value)
TypeError: expected string or buffer

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails fro

Re: Problems with migrations cleaning up a date field

2017-06-09 Thread Lee Hinde
I should add, this project is in 1.8.x. I'm working around the problem by
skipping the migration.

-- 
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/CA%2BePoMxnZ_LHcKx-2R_fX7WUwo-qkhxTDZdBcO39zX%3DH2xBBBA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problems with migrations cleaning up a date field

2017-06-09 Thread James Schneider
On Jun 9, 2017 6:09 PM, "Lee Hinde"  wrote:

I'm having problems with a migration after cleaning up an oddity with a
date field and I'm not sure how to fix it.  Any advice appreciated.

I made this change to a date field:

-start_date = models.DateField(db_index=True, default=False,
-  help_text="The date enrollment can begin
this Season.")
+start_date = models.DateField(db_index=True, help_text="The date
enrollment can begin this Season.")

I'm not sure how a default of False ever made it, but I ran across it and
fixed it.


Have you verified that every row has a value for start_date? The error
sounds like either your start_dates are missing/have null values, or you
have a bad value somewhere.

Quite honestly this sounds like a bug in the migration system if that's the
case. I'm pretty sure it should ask what value to use as a filler value
during the migration, although I haven't had a change like that in a while.

-James

-- 
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/CA%2Be%2BciX6gqeKfCTpeMUKPp_rrX_g4Fneq2rjKW5nHGDxbThp6g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


What is the best approach

2017-06-09 Thread Arshdeep Singh


down votefavorite 


I was thinking about making a Hostel Allocation Web application. It has 
models, Student, Room, Hostel. What I want is to create a function that 
allocates students after each year. For that, I thought in the student view 
each student after completing his four years of stay can click on vacate 
hostel after completing his degree, and for others, I want to create 
something that allocates them, Now there are certain constraints, there are 
Undergraduate students with degree period 4 years and each year has access 
to different types of rooms, First-year triple sharing, second and 
third-year double sharing and fourth-year single rooms. Also, a Hostel has 
Ph.D. students as well but their stay period is not defined.

So, what I was thinking is that First years should be allotted by uploading 
a CSV file and I have made that part, So the next part is to allot 
subsequent years based on their preferences, So how could I make something 
like this in Django that allows them to make it based on their preference, 
I was thinking each student would be given a unique token, and while 
filling for rooms one student can do for a room, and that token needs to be 
entered. Is this the right way or should I do something else. I am a newbie 
please suggest me a good way to do this.

models.py

class Student(models.Model):
name = models.CharField(max_length = 40,help_text = "Name of the student")
entry_number = models.CharField(max_length = 11,help_text = "Entry Number 
of a student")
hostel_name = models.ForeignKey('Hostel', on_delete = models.SET_NULL,null 
= True)
room = models.ForeignKey('Room',on_delete = models.SET_NULL,null = True)
CHOICES = (
('m','Male'),
('f','Female'),
('e','Engaged'),
)
gender = models.CharField(max_length=1,choices=CHOICES)
def __str__(self):
   return '%s, %s' % (self.name,self.entry_number)
def get_absolute_url(self):
return reverse('student-detail',args=[str(self.id)])
class Meta:
verbose_name="Student Record"

class Hostel(models.Model):
name= models.CharField(max_length= 15)
locality= models.URLField(max_length= 200, blank= True, 
default='',help_text='Google maps URL of the hostel')
total_rooms= models.PositiveSmallIntegerField(null=True, blank =True)
CHOICES = (
('m', 'Male'),
('f', 'Female'),
('e', 'Engaged'),
)
gender = models.CharField(max_length=1, choices=CHOICES, 
verbose_name=_('Type of Hostel'), help_text='Either Boys/Girls or Married 
students Hostel')
def __str__(self):
return  self.name
def get_absolute_url(self):
return reverse('hostel-detail',args=[str(self.id)])
class Meta:
verbose_name="Hostel Record"

class Room(models.Model):
hostel= models.ForeignKey(Hostel, on_delete=models.CASCADE)
name= models.CharField(max_length = 5)
floor= models.CharField(max_length = 1, blank=True)
wing= models.CharField(max_length = 1, blank=True)
comment= models.CharField(max_length = 100,blank=True, default = "comment 
here")
room_capacity = 
models.PositiveSmallIntegerField(validators=[MaxValueValidator(3),])
room_accomodation= models.PositiveSmallIntegerField()

def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('room-detail',args=[str(self.id)])
class Meta:
verbose_name="Room Record

-- 
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/912b30a8-5ca8-4ea6-ba09-29654d1943e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.