I am really stuck in my code. I have this printing project I have created. I wanted that in my student profile class, it will automatically update the the total printout and the available printout after the user has inputted the corresponding value in the prinout class. and also the report generation will be by computer lab rooms. this is done in the default administration of django. Im using by the way python 2.7, django 1.5.2, Eclipse Standard/SDK and mysql workbench 5.2.47 CE. thanks. Attach here is a zip file of my programs.
*model.py*
>
> class Student_Profile(models.Model):
> id_number = models.CharField(max_length= 60, unique = True)
> first_name = models.CharField(max_length= 60)
> middle_name = models.CharField(max_length= 60)
> last_name = models.CharField(max_length= 60)
> active = models.BooleanField()
> date_created = models.DateTimeField('date created')
>
>
> def my_property(self):
> return self.last_name + ', ' + self.first_name + ' ' + self.middle_name
> my_property.short_description = "Full name of the person"
>
> name = property(my_property)
>
> def __unicode__(self):
> return u'%s, %s %s' % (self.last_name, self.first_name, self.middle_name)
>
>
> class Semester(models.Model):
> #I manually encode it to mysql workbenc
> semester = models.CharField(max_length= 60)
>
> def __unicode__(self):
> return self.semester
>
>
> class Student_Subject(models.Model):
>
> Student_Profile = models.ForeignKey(Student_Profile)
> subject_code = models.CharField(max_length= 60)
> teacher = models.CharField(max_length= 60)
> total_printout = models.PositiveSmallIntegerField(default=0)
> available_printout = models.PositiveSmallIntegerField(default=50)
> room = models.CharField(max_length= 60)
> semester = models.ForeignKey(Semester)
> school_year = models.CharField(max_length= 30)
> date_joined = models.DateField()
>
>
>
> def __unicode__(self):
> return self.subject_code
>
>
> class Room(models.Model):
> #I manually encode it to mysql workbenc
> room = models.CharField(max_length= 60)
>
> def __unicode__(self):
> return self.room
>
>
> class Printout(models.Model):
> Student_Name = models.ForeignKey(Student_Profile)
> Subject = ChainedForeignKey(
> Student_Subject,
> chained_field="Student_Name",
> chained_model_field="Student_Profile",
> show_all=False,
> auto_choose=True
> )
> room = models.ForeignKey(Room)
> printout = models.PositiveSmallIntegerField(default=0)
> created_by = models.ForeignKey(User, null=True, blank=True)
> date_created = models.DateField()
> time_created = models.TimeField()
>
> *admin.py*
>
> from django.contrib import admin
> from models import Student_Profile, Student_Subject, Printout
>
>
> class Student_SubjectInline(admin.TabularInline):
> model = Student_Subject
> extra = 1
>
> class Student_ProfileAdmin(admin.ModelAdmin):
>
> inlines = (Student_SubjectInline,)
> search_fields = ['last_name', 'first_name', 'id_number']
> list_display = ('name', 'id_number')
> ordering = ('last_name', 'first_name', 'middle_name',)
> pass
>
> admin.site.register(Student_Profile, Student_ProfileAdmin)
>
>
>
> from django.contrib.auth.models import User
>
> class PrintoutAdmin(admin.ModelAdmin):
>
> list_display = ('room', 'created_by', 'Student_Name', 'printout',
> 'Subject', 'date_created', 'time_created' )
> #search_fields = ['room']
> list_filter = ['room']
>
> def formfield_for_foreignkey(self, db_field, request, **kwargs):
> if db_field.name == 'created_by':
> kwargs['queryset'] = User.objects.filter(username=request.user.username)
> return super(PrintoutAdmin, self).formfield_for_foreignkey(db_field,
> request, **kwargs)
>
> def get_readonly_fields(self, request, obj=None):
> if obj is not None:
> return self.readonly_fields + ('created_by',)
> return self.readonly_fields
>
> def add_view(self, request, form_url="", extra_context=None):
> data = request.GET.copy()
> data['created_by'] = request.user
> request.GET = data
> return super(PrintoutAdmin, self).add_view(request, form_url="",
> extra_context=extra_context)
> pass
>
> admin.site.register(Printout, PrintoutAdmin)
>
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
printing.rar
Description: application/rar

