मैं सिर्फ django tastypie से शुरू कर रहा हूं, और मैं इसके बारे में उत्साहित हूं। मेरा प्रश्न: मैं व्यवस्थापक दृश्य में एक ही सुविधा की खोज कर रहा हूं: विदेशी वस्तुओं के लिए निर्दिष्ट करें कि अन्य ऑब्जेक्ट्स की सूची प्रतिक्रिया में क्या देखें और विस्तृत प्रतिक्रिया में क्या देखें।Django tastypie: विस्तृत अनुरोध में रिसोर्स शो अलग-अलग अनुरोध अनुरोध के रूप में अलग है
class Location(models.Model):
name = models.CharField(max_length=256, blank=True)
longitude = models.FloatField(blank=True, default=0.0)
latitude = models.FloatField(blank=True, default=0.0)
description = models.CharField(max_length=256, blank=True)
shortname = models.CharField(max_length=256, blank=True)
tooltiptext = models.CharField(max_length=1000, blank=True)
locationtype = models.ForeignKey(LocationType, blank=True, null=True)
public_anonymous = models.BooleanField(default=False, blank=False, null=False)
public_authorized = models.BooleanField(default=False, blank=False, null=False)
def __str__(self):
return '%s' % (self.name)
class Variable(models.Model):
abbreviation = models.CharField(max_length=64, unique=True)
name = models.CharField(max_length=256, blank=True)
unit = models.CharField(max_length=64, blank=True)
def __str__(self):
return '%s [%s]' % (self.name, self.unit)
class Timeseries(models.Model):
locationkey = models.ForeignKey(Location)
variablekey = models.ForeignKey(Variable)
tstypekey = models.ForeignKey(TimeseriesType)
def __str__(self):
return '%s: %s (%s)' % (self.locationkey.name, self.variablekey.name, self.tstypekey.name)
और इन API के लिए मेरे संसाधन हैं::
चलो कहते हैं कि यह मेरा simplyfied मॉडल है जाने
class LocationResource(ModelResource):
class Meta:
queryset = Location.objects.all()
resource_name = 'location'
excludes = ['public_anonymous', 'public_authorized']
authentication = BasicAuthentication()
authorization = DjangoAuthorization()
class VariableResource(ModelResource):
class Meta:
queryset = Variable.objects.all()
resource_name = 'variable'
authentication = BasicAuthentication()
authorization = DjangoAuthorization()
class TimeseriesTypeResource(ModelResource):
class Meta:
queryset = TimeseriesType.objects.all()
resource_name = 'timeseriestype'
authentication = BasicAuthentication()
authorization = DjangoAuthorization()
class TimeseriesResource(ModelResource):
location = fields.ForeignKey(LocationResource, 'locationkey', full=False)
variable = fields.ForeignKey(VariableResource, 'variablekey', full=False)
timeseriestype = fields.ForeignKey(TimeseriesTypeResource, 'tstypekey', full=False)
class Meta:
queryset = Timeseries.objects.all()
resource_name = 'timeseries'
authentication = BasicAuthentication()
authorization = DjangoAuthorization()
TimeseriesResource में यदि आप full=False
उपयोग करते हैं, तो आप सिर्फ एक साथ एक यूआरएल मिल आईडी, यदि आप full=True
का उपयोग करते हैं तो आपको सारी जानकारी मिलती है। वास्तव में स्थान में बहुत अधिक जानकारी है। मुझे पूर्ण = 'झूठी' की तुलना में बस थोड़ी अधिक जानकारी चाहिए, लेकिन full=True
का उपयोग करके सभी जानकारी नहीं। मैं बहिष्कृत विकल्प का उपयोग नहीं करना चाहता, क्योंकि मेरे पास विस्तृत जानकारी में या स्थान ऑब्जेक्ट की सूची में इसकी जानकारी नहीं है।
विकल्पों में से एक विकल्प जो मैं सोच रहा था, उसी वस्तु के लिए 2 संसाधन बना रहा है, लेकिन यह सबसे अच्छा समाधान नहीं लगता है (लेकिन मुझे लगता है कि यह काम करेगा)। वैसे: मैंने इस विकल्प पर सोचा, काम नहीं करेगा (धन्यवाद), bmihelac (धन्यवाद) के जवाब में usgested कामकाज का बेहतर उपयोग करें।
हालांकि ... वैकल्पिक हल की कोशिश कर रहा ... मुझे एक नया सवाल की ओर जाता है, देखें:
django-tastypie: Cannot access bundle.request in dehydrate(self,bundle)
में उत्तर में स्निपेट शामिल है और मैं इसे वोट दूंगा :) – ashwoods
धन्यवाद, कम से कम मुझे पता है कि कोई और खोज नहीं है! कामकाज अच्छा दिखता है (सही नहीं है, लेकिन यह चाल करना चाहिए) –
एक सुखद अद्यतन के लिए मेरा जवाब देखें! – mlissner