src/hp/forms.py
changeset 41 b6010b3d6ea8
child 45 316a0101512e
equal deleted inserted replaced
40:342f180b09ec 41:b6010b3d6ea8
       
     1 # -*- coding: utf-8 -*-
       
     2 '''
       
     3 Created on Nov 14, 2012
       
     4 
       
     5 @author: ymh
       
     6 '''
       
     7 
       
     8 from django import forms
       
     9 from .models import VideoKCRel
       
    10 import requests
       
    11 from . import settings
       
    12 
       
    13 class VideoKCRelForm(forms.ModelForm):
       
    14     
       
    15     iri_id = forms.CharField(max_length=255, widget=forms.widgets.Select()) 
       
    16 
       
    17     def __init__(self, *args, **kwargs):
       
    18         super(VideoKCRelForm, self).__init__(*args, **kwargs)
       
    19         
       
    20         url = settings.LDT_API_URL + "contents/"
       
    21         #limit=20&offset=20
       
    22         r = requests.get(url)        
       
    23         self.fields['iri_id'].widget.choices = [(content['iri_id'], content['title']) for content in r.json['objects']]
       
    24         
       
    25     class Meta:
       
    26         model = VideoKCRel
       
    27