コード例 #1
0
ファイル: core.py プロジェクト: mena18/Courses-platform
 def create_course(self):
     course = Course()
     course.title= "just_created"
     course.description = "course_desc"
     course.instructor_id = 1
     course.save()
     return course
コード例 #2
0
    def test_update_courses_valid(self):
        course = Course()
        course.title = "just_created"
        course.description = "course_desc"
        course.instructor_id = 1
        course.save()

        data = {'title': 'new_title', 'description': 'new desc'}

        response = self.get_instructor_owner.put(reverse(
            'courses_api:course-detail', args=[course.id]),
                                                 format='json',
                                                 data=data)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['title'], data['title'])
        self.assertEqual(response.data['description'], data['description'])
コード例 #3
0
ファイル: notes.py プロジェクト: zeromars/treehouse
python manage.py startapp courses

#id is automatically added in django
python manage.py makemigrations
# python manage.py makemigrations courses (to be more specific)

python manage.py migrate

python manage.py shell

from courses.models import Course
Course.objects.all()

c = Course()
c.title = "Python Basics"
c.description = "Learn the basics of python"
c.save()

Course(title="Python Collections", description="Learn abouyt lists , dict and tuples").save()

Course.objects.create(title="Object Oriented Python", description="Learn about python's classes")

#python manage.py shell opens a Python shell with Django's configuration already loaded.
#Model.save() will save an in-memory instance of a model to the database.
#Model.create() will save an in-memory instance of a model to the database and return the newly-created object.
#Model.filter(attribute=value) will get a QuerySet of all instances of the Model that match the attribute values. You can change these values with other comparisons, too, like gte or in. Find out more here
#include() allows you to include a list of URLs from another module. It will accept the variable name or a string with a dotted path to the default urlpatterns variable.
#If you don't have include() in your urls.py (more recent versions of Django have removed it), add it to the import line that imports url. That line will now look like from django.conf.urls import url, include.
#This is the Comprehensions Workshop that's mentioned in the video. Comprehensions are a great way of doing quick work with iterables.

# python manage.py createsuperuser will create a new superuser, or a user that's allowed to log into the admin area with all permissions.
コード例 #4
0
ファイル: splitcourses.py プロジェクト: shacker/djcc
for t in tempset:
    o = Offering.objects.filter(ccn=t)[:1]
    # o looks like a single object but is actually a queryset consisting of one record.
    # To  get the first actual object in it, use o[0]
    offering = o[0]
    print
    print offering
    
    # Create a Course record based on that
    course = Course()
    course.title = offering.title
    course.ccn = offering.ccn
    course.cstring = offering.cstring
    course.units = offering.units
    course.type = offering.type
    course.description = offering.description
    course.restrictions = offering.restrictions
    course.save()
    
    # Programs is many to many. Loop through and re-create
    for p in offering.programs.all():
        course.programs.add(p)
        
    # title = models.CharField(max_length=384)
    # ccn = models.CharField('CCN',max_length=384, blank=True)
    # cstring = models.ForeignKey(Cstring,verbose_name='Course String',help_text="e.g. J-200, but without the J")
    # units = models.IntegerField(choices=constants.UNIT_TYPE_CHOICES)
    # type = models.IntegerField(choices=constants.COURSE_TYPE_CHOICES)
    # description = models.TextField()
    # restrictions = models.TextField(null=True,blank=True)
    # programs = models.ManyToManyField(Program,blank=True)
コード例 #5
0
for t in tempset:
    o = Offering.objects.filter(ccn=t)[:1]
    # o looks like a single object but is actually a queryset consisting of one record.
    # To  get the first actual object in it, use o[0]
    offering = o[0]
    print
    print offering

    # Create a Course record based on that
    course = Course()
    course.title = offering.title
    course.ccn = offering.ccn
    course.cstring = offering.cstring
    course.units = offering.units
    course.type = offering.type
    course.description = offering.description
    course.restrictions = offering.restrictions
    course.save()

    # Programs is many to many. Loop through and re-create
    for p in offering.programs.all():
        course.programs.add(p)

    # title = models.CharField(max_length=384)
    # ccn = models.CharField('CCN',max_length=384, blank=True)
    # cstring = models.ForeignKey(Cstring,verbose_name='Course String',help_text="e.g. J-200, but without the J")
    # units = models.IntegerField(choices=constants.UNIT_TYPE_CHOICES)
    # type = models.IntegerField(choices=constants.COURSE_TYPE_CHOICES)
    # description = models.TextField()
    # restrictions = models.TextField(null=True,blank=True)
    # programs = models.ManyToManyField(Program,blank=True)