SHARE
TWEET

Untitled

Maycon_py Oct 21st, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Model2(models.Model):
  2.     field_1 = models.CharField()
  3.     field_2 = models.CharField()
  4.     field_3 = models.ForeingKey(Model1)
  5.  
  6. class CustomView:
  7.     def __init__(objeto):
  8.         custom_field_1 = objeto.field_1
  9.         custom_field_2 = objeto.field_2
  10.         custom_field_3 = objeto.field_3.model1.field_1
  11.    
  12.     def data():
  13.         return self.__dict__
  14.  
  15. dados = CustomView(Model1.objects.select_related('model1').all())
  16.  
  17. dados = [
  18.     {custom_field_1: "...", custom_field_2: "..."},
  19.     {custom_field_1: "...", custom_field_2: "..."},
  20.     ...
  21. ]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top