How to create simple custom field in django?2019 Community Moderator ElectionHow to merge two dictionaries in a single expression?How do I check if a list is empty?How do I check whether a file exists without exceptions?How can I safely create a nested directory in Python?How do I sort a dictionary by value?Does Django scale?How do I list all files of a directory?Radio buttons in django adminHow to expose some specific fields of model_b based on a field of model_a?How to define Mode with generic ForeignKey in Django

Emojional cryptic crossword

Is "inadequate referencing" a euphemism for plagiarism?

Is a square zero matrix positive semidefinite?

Pre-Employment Background Check With Consent For Future Checks

Don't understand why (5 | -2) > 0 is False where (5 or -2) > 0 is True

Why is indicated airspeed rather than ground speed used during the takeoff roll?

TDE Master Key Rotation

Why didn’t Eve recognize the little cockroach as a living organism?

Did Nintendo change its mind about 68000 SNES?

Print last inputted byte

Isn't the word "experience" wrongly used in this context?

What are rules for concealing thieves tools (or items in general)?

How to read string as hex number in bash?

How to test the sharpness of a knife?

Why didn't Héctor fade away after this character died in the movie Coco?

If I cast the Enlarge/Reduce spell on an arrow, what weapon could it count as?

What kind of footwear is suitable for walking in micro gravity environment?

Difficulty understanding group delay concept

Do native speakers use "ultima" and "proxima" frequently in spoken English?

Help with identifying unique aircraft over NE Pennsylvania

Is VPN a layer 3 concept?

Friend wants my recommendation but I don't want to

is this saw blade faulty?

10 year ban after applying for a UK student visa



How to create simple custom field in django?



2019 Community Moderator ElectionHow to merge two dictionaries in a single expression?How do I check if a list is empty?How do I check whether a file exists without exceptions?How can I safely create a nested directory in Python?How do I sort a dictionary by value?Does Django scale?How do I list all files of a directory?Radio buttons in django adminHow to expose some specific fields of model_b based on a field of model_a?How to define Mode with generic ForeignKey in Django










0















I want to create two additional properties of TextField such as property1 and property2 so that I can access them in template like



% for field in form %
field.property1
field.property2
% endfor %


my current model looks like



class ResponseModel(models.Model):
author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
ans1 = models.TextField()
ans2 = models.TextField()
submit_count = models.IntegerField(default=0)

def __str__(self):
return str(self.author) + str(self.submit_count)









share|improve this question




























    0















    I want to create two additional properties of TextField such as property1 and property2 so that I can access them in template like



    % for field in form %
    field.property1
    field.property2
    % endfor %


    my current model looks like



    class ResponseModel(models.Model):
    author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    ans1 = models.TextField()
    ans2 = models.TextField()
    submit_count = models.IntegerField(default=0)

    def __str__(self):
    return str(self.author) + str(self.submit_count)









    share|improve this question


























      0












      0








      0








      I want to create two additional properties of TextField such as property1 and property2 so that I can access them in template like



      % for field in form %
      field.property1
      field.property2
      % endfor %


      my current model looks like



      class ResponseModel(models.Model):
      author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
      ans1 = models.TextField()
      ans2 = models.TextField()
      submit_count = models.IntegerField(default=0)

      def __str__(self):
      return str(self.author) + str(self.submit_count)









      share|improve this question
















      I want to create two additional properties of TextField such as property1 and property2 so that I can access them in template like



      % for field in form %
      field.property1
      field.property2
      % endfor %


      my current model looks like



      class ResponseModel(models.Model):
      author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
      ans1 = models.TextField()
      ans2 = models.TextField()
      submit_count = models.IntegerField(default=0)

      def __str__(self):
      return str(self.author) + str(self.submit_count)






      python django django-custom-field






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 11:17









      Ajanyan Pradeep

      434111




      434111










      asked Mar 7 at 18:38









      PritamPritam

      103




      103






















          1 Answer
          1






          active

          oldest

          votes


















          0














          in order to access the model properties in the template you should pass them through the view.py:



          **views.py**

          from .models import *

          def index(request):
          context=
          'form': ResponseModel


          return render(request, 'path/to/template', context)


          And in index.html (Template):



          % for field in form %
          field.property1
          field.property2
          % endfor %


          That should work just fine, let me know if you got it.






          share|improve this answer























          • I couldn't make myself clear I'm sorry. I want to create two additional properties of TextField so that I can access them. I shall edit my question.

            – Pritam
            Mar 8 at 10:37











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050667%2fhow-to-create-simple-custom-field-in-django%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          in order to access the model properties in the template you should pass them through the view.py:



          **views.py**

          from .models import *

          def index(request):
          context=
          'form': ResponseModel


          return render(request, 'path/to/template', context)


          And in index.html (Template):



          % for field in form %
          field.property1
          field.property2
          % endfor %


          That should work just fine, let me know if you got it.






          share|improve this answer























          • I couldn't make myself clear I'm sorry. I want to create two additional properties of TextField so that I can access them. I shall edit my question.

            – Pritam
            Mar 8 at 10:37
















          0














          in order to access the model properties in the template you should pass them through the view.py:



          **views.py**

          from .models import *

          def index(request):
          context=
          'form': ResponseModel


          return render(request, 'path/to/template', context)


          And in index.html (Template):



          % for field in form %
          field.property1
          field.property2
          % endfor %


          That should work just fine, let me know if you got it.






          share|improve this answer























          • I couldn't make myself clear I'm sorry. I want to create two additional properties of TextField so that I can access them. I shall edit my question.

            – Pritam
            Mar 8 at 10:37














          0












          0








          0







          in order to access the model properties in the template you should pass them through the view.py:



          **views.py**

          from .models import *

          def index(request):
          context=
          'form': ResponseModel


          return render(request, 'path/to/template', context)


          And in index.html (Template):



          % for field in form %
          field.property1
          field.property2
          % endfor %


          That should work just fine, let me know if you got it.






          share|improve this answer













          in order to access the model properties in the template you should pass them through the view.py:



          **views.py**

          from .models import *

          def index(request):
          context=
          'form': ResponseModel


          return render(request, 'path/to/template', context)


          And in index.html (Template):



          % for field in form %
          field.property1
          field.property2
          % endfor %


          That should work just fine, let me know if you got it.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 8 at 10:17









          Dre RossDre Ross

          12116




          12116












          • I couldn't make myself clear I'm sorry. I want to create two additional properties of TextField so that I can access them. I shall edit my question.

            – Pritam
            Mar 8 at 10:37


















          • I couldn't make myself clear I'm sorry. I want to create two additional properties of TextField so that I can access them. I shall edit my question.

            – Pritam
            Mar 8 at 10:37

















          I couldn't make myself clear I'm sorry. I want to create two additional properties of TextField so that I can access them. I shall edit my question.

          – Pritam
          Mar 8 at 10:37






          I couldn't make myself clear I'm sorry. I want to create two additional properties of TextField so that I can access them. I shall edit my question.

          – Pritam
          Mar 8 at 10:37




















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050667%2fhow-to-create-simple-custom-field-in-django%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

          List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229