<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments for ontehfritz - Application Development and Stuff</title>
	<atom:link href="http://ontehfritz.wordpress.com/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://ontehfritz.wordpress.com</link>
	<description>.Net, Programming, Application Development and Stuff</description>
	<lastBuildDate>Thu, 14 May 2009 17:00:38 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>Comment on Django Forms &#8211; ChoiceField and MultipleChoiceField by ontehfritz</title>
		<link>http://ontehfritz.wordpress.com/2009/02/15/django-forms-choicefield-and-multiplechoicefield/#comment-15</link>
		<dc:creator>ontehfritz</dc:creator>
		<pubDate>Thu, 14 May 2009 17:00:38 +0000</pubDate>
		<guid isPermaLink="false">http://ontehfritz.wordpress.com/?p=61#comment-15</guid>
		<description>Well django does most of the work for you when setup correctly. 

you have a view like so:
[sourcecode language=&#039;python&#039;]
def render_questions(request):
.
.  Some code here 
.

   if request.method == &#039;POST&#039;:
        form_list = create_question_forms(request.POST)

        for form in form_list:
            if form.is_valid():
                form.save()
            
        return HttpResponseRedirect(some_url) #direct to url after
    else:
            form_list = create_question_forms()

    return render_to_response(&#039;your_template.html&#039;, {&#039;forms&#039;: form_list})
[/sourcecode]

the request.POST on submit contains a QueryDict object that contains all of your submitted data, so pass this to your create_question_forms object, which is defined like this: 

[sourcecode language=&#039;python&#039;]
def create_question_forms(data=None):
    question_list = ... # get all your questions from here via db or where ever your questions are stored
    form_list = []
   
   for pos, question in enumerate(question_list):
            #data is the request.POST and if it is there will populate you questions with the user choices
            form_list.append(QuestionMulipleChoiceRadio(question, data, prefix=pos))

    return form_list
[/sourcecode]

Then your Question form would be something like this: 
[sourcecode language=&#039;python&#039;]
class QuestionCheckBox(forms.Form):
    answers = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, label=&quot;&quot;)
    def __init__(self, question, *args, **kwargs):
        super(QuestionCheckBox, self).__init__(*args, **kwargs)
        self.text = question.text
        self.question = question
     
        answers = question.answer_set.all().order_by(&#039;index&#039;)
        self.fields[&#039;answers&#039;].choices = [(str(i), a.text) for i, a in enumerate(answers)]
        self.choices_dict = dict(self.fields[&#039;answers&#039;].choices)
        self.count = count

    def save(self, commit=True):
      ...
      Some more code, do what you want
      ....
[/sourcecode]      
Confusing huh? Well as much detail as I can get into right now. But basically when the user submits the data with the post.Tehn you pass the post to the view; then pass that data to your form and it will rebuild it with the data from the request.POST; then once the form is valid and the save method is called. You can save it to where ever you like DB, XML and JSON file whatever it is up to you. Hope this helps!</description>
		<content:encoded><![CDATA[<p>Well django does most of the work for you when setup correctly. </p>
<p>you have a view like so:</p>
<pre class="brush: python;">
def render_questions(request):
.
.  Some code here
.

   if request.method == 'POST':
        form_list = create_question_forms(request.POST)

        for form in form_list:
            if form.is_valid():
                form.save()

        return HttpResponseRedirect(some_url) #direct to url after
    else:
            form_list = create_question_forms()

    return render_to_response('your_template.html', {'forms': form_list})
</pre>
<p>the request.POST on submit contains a QueryDict object that contains all of your submitted data, so pass this to your create_question_forms object, which is defined like this: </p>
<pre class="brush: python;">
def create_question_forms(data=None):
    question_list = ... # get all your questions from here via db or where ever your questions are stored
    form_list = []

   for pos, question in enumerate(question_list):
            #data is the request.POST and if it is there will populate you questions with the user choices
            form_list.append(QuestionMulipleChoiceRadio(question, data, prefix=pos))

    return form_list
</pre>
<p>Then your Question form would be something like this: </p>
<pre class="brush: python;">
class QuestionCheckBox(forms.Form):
    answers = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, label="")
    def __init__(self, question, *args, **kwargs):
        super(QuestionCheckBox, self).__init__(*args, **kwargs)
        self.text = question.text
        self.question = question

        answers = question.answer_set.all().order_by('index')
        self.fields['answers'].choices = [(str(i), a.text) for i, a in enumerate(answers)]
        self.choices_dict = dict(self.fields['answers'].choices)
        self.count = count

    def save(self, commit=True):
      ...
      Some more code, do what you want
      ....
</pre>
<p>Confusing huh? Well as much detail as I can get into right now. But basically when the user submits the data with the post.Tehn you pass the post to the view; then pass that data to your form and it will rebuild it with the data from the request.POST; then once the form is valid and the save method is called. You can save it to where ever you like DB, XML and JSON file whatever it is up to you. Hope this helps!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on .Net Entity Framework Updating Objects in N-Tier Environment by ontehfritz</title>
		<link>http://ontehfritz.wordpress.com/2008/11/21/net-entity-framework-updating-objects-in-n-tier-environment/#comment-14</link>
		<dc:creator>ontehfritz</dc:creator>
		<pubDate>Thu, 14 May 2009 14:17:33 +0000</pubDate>
		<guid isPermaLink="false">http://ontehfritz.wordpress.com/?p=20#comment-14</guid>
		<description>Is your primary key compound, meaning more than one field makes the primary key? This can also cause issues with the entity framework. Especially if they are a foreign key. What I have done to make life easier is create an additional identity key and make that the primary key. This way the entity framework can use this identity as its identifier, you can still have the foreign keys, but just not as primary key. Also if it is many-to-many relationship between the tables can cause issues as well. You will have to have mapping table to make it work correctly and the foreign keys cannot be part of the primary key. 

If you want the records to be unique by the foreign keys then put a unique constraint on the table with those fields instead of making it the primary key. Then add the identity field as the primary. This should work. Kind of weird but that is what you have to do, to make your tables to play nicely with Entity framework.</description>
		<content:encoded><![CDATA[<p>Is your primary key compound, meaning more than one field makes the primary key? This can also cause issues with the entity framework. Especially if they are a foreign key. What I have done to make life easier is create an additional identity key and make that the primary key. This way the entity framework can use this identity as its identifier, you can still have the foreign keys, but just not as primary key. Also if it is many-to-many relationship between the tables can cause issues as well. You will have to have mapping table to make it work correctly and the foreign keys cannot be part of the primary key. </p>
<p>If you want the records to be unique by the foreign keys then put a unique constraint on the table with those fields instead of making it the primary key. Then add the identity field as the primary. This should work. Kind of weird but that is what you have to do, to make your tables to play nicely with Entity framework.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on .Net Entity Framework Updating Objects in N-Tier Environment by dan</title>
		<link>http://ontehfritz.wordpress.com/2008/11/21/net-entity-framework-updating-objects-in-n-tier-environment/#comment-13</link>
		<dc:creator>dan</dc:creator>
		<pubDate>Thu, 14 May 2009 11:10:23 +0000</pubDate>
		<guid isPermaLink="false">http://ontehfritz.wordpress.com/?p=20#comment-13</guid>
		<description>sorry...i got the problem: my foreign key was part of my primary key, hence the exception!
Any idea about solving my issue?</description>
		<content:encoded><![CDATA[<p>sorry&#8230;i got the problem: my foreign key was part of my primary key, hence the exception!<br />
Any idea about solving my issue?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on .Net Entity Framework Updating Objects in N-Tier Environment by dan</title>
		<link>http://ontehfritz.wordpress.com/2008/11/21/net-entity-framework-updating-objects-in-n-tier-environment/#comment-12</link>
		<dc:creator>dan</dc:creator>
		<pubDate>Thu, 14 May 2009 08:46:34 +0000</pubDate>
		<guid isPermaLink="false">http://ontehfritz.wordpress.com/?p=20#comment-12</guid>
		<description>ps. the exception is raised in the Update method, while trying to update the original Item relationships</description>
		<content:encoded><![CDATA[<p>ps. the exception is raised in the Update method, while trying to update the original Item relationships</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on .Net Entity Framework Updating Objects in N-Tier Environment by dan</title>
		<link>http://ontehfritz.wordpress.com/2008/11/21/net-entity-framework-updating-objects-in-n-tier-environment/#comment-11</link>
		<dc:creator>dan</dc:creator>
		<pubDate>Thu, 14 May 2009 07:28:14 +0000</pubDate>
		<guid isPermaLink="false">http://ontehfritz.wordpress.com/?p=20#comment-11</guid>
		<description>here is my code:

/* ....  */
D updateD = GetDByID(input, input, input);
            // SUPPOSE: this is the Client Side
            EntityReference&lt;B&gt; b = new EntityReference&lt;B&gt;();
            b.EntityKey = b2.EntityKey;
            updateD.BReference = b;

            EntityReference c = new EntityReference();
            c.EntityKey = c2.EntityKey;
            updateD.CReference = c;

            updateD.dAttribute1 = 999999999;

            Update(updateD); 

/* ....  */


private void Update(System.Data.Objects.DataClasses.EntityObject o)
        {
            EntityKey key;
            Object originalItem;

            using (TEST1Entities t2e = new TEST1Entities())
            {
                key = t2e.CreateEntityKey(o.EntityKey.EntitySetName, o);

                if (t2e.TryGetObjectByKey(key, out originalItem))
                {
                    t2e.ApplyPropertyChanges(key.EntitySetName, o);

                    foreach (var entityrelationship in ((IEntityWithRelationships)originalItem).RelationshipManager.GetAllRelatedEnds())
                    {
                        var oldRef = (EntityReference)entityrelationship; // as EntityReference; // EntityReference;

                        if (oldRef != null)
                        {
                            var newRef = ((IEntityWithRelationships)o).RelationshipManager.GetRelatedEnd(oldRef.RelationshipName, oldRef.TargetRoleName) as EntityReference;
                            oldRef.EntityKey = newRef.EntityKey;
                        }
                    }
                }

                t2e.SaveChanges();
            }
               
        }

        private D GetDByID(int A, int B, int C)
        { 
            using (TEST1Entities t1e = new TEST1Entities()){
                List dList= (t1e.D.Where(d =&gt; d.aId==A &amp;&amp; d.bId==B &amp;&amp; d.cId==C)).ToList();
                D retD = dList[0];
                t1e.Detach(retD);
                return retD;
            }
        
        }</description>
		<content:encoded><![CDATA[<p>here is my code:</p>
<p>/* &#8230;.  */<br />
D updateD = GetDByID(input, input, input);<br />
            // SUPPOSE: this is the Client Side<br />
            EntityReference<b> b = new EntityReference</b><b>();<br />
            b.EntityKey = b2.EntityKey;<br />
            updateD.BReference = b;</p>
<p>            EntityReference c = new EntityReference();<br />
            c.EntityKey = c2.EntityKey;<br />
            updateD.CReference = c;</p>
<p>            updateD.dAttribute1 = 999999999;</p>
<p>            Update(updateD); </p>
<p>/* &#8230;.  */</p>
<p>private void Update(System.Data.Objects.DataClasses.EntityObject o)<br />
        {<br />
            EntityKey key;<br />
            Object originalItem;</p>
<p>            using (TEST1Entities t2e = new TEST1Entities())<br />
            {<br />
                key = t2e.CreateEntityKey(o.EntityKey.EntitySetName, o);</p>
<p>                if (t2e.TryGetObjectByKey(key, out originalItem))<br />
                {<br />
                    t2e.ApplyPropertyChanges(key.EntitySetName, o);</p>
<p>                    foreach (var entityrelationship in ((IEntityWithRelationships)originalItem).RelationshipManager.GetAllRelatedEnds())<br />
                    {<br />
                        var oldRef = (EntityReference)entityrelationship; // as EntityReference; // EntityReference;</p>
<p>                        if (oldRef != null)<br />
                        {<br />
                            var newRef = ((IEntityWithRelationships)o).RelationshipManager.GetRelatedEnd(oldRef.RelationshipName, oldRef.TargetRoleName) as EntityReference;<br />
                            oldRef.EntityKey = newRef.EntityKey;<br />
                        }<br />
                    }<br />
                }</p>
<p>                t2e.SaveChanges();<br />
            }</p>
<p>        }</p>
<p>        private D GetDByID(int A, int B, int C)<br />
        {<br />
            using (TEST1Entities t1e = new TEST1Entities()){<br />
                List dList= (t1e.D.Where(d =&gt; d.aId==A &amp;&amp; d.bId==B &amp;&amp; d.cId==C)).ToList();<br />
                D retD = dList[0];<br />
                t1e.Detach(retD);<br />
                return retD;<br />
            }</p>
<p>        }</b></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on .Net Entity Framework Updating Objects in N-Tier Environment by ontehfritz</title>
		<link>http://ontehfritz.wordpress.com/2008/11/21/net-entity-framework-updating-objects-in-n-tier-environment/#comment-10</link>
		<dc:creator>ontehfritz</dc:creator>
		<pubDate>Wed, 13 May 2009 14:15:51 +0000</pubDate>
		<guid isPermaLink="false">http://ontehfritz.wordpress.com/?p=20#comment-10</guid>
		<description>I would have to see more of the code. But I will make some assumptions based on what you have posted. 

oldRef.EntityKey = newRef.EntityKey;

Looks like you are taking an old entity key and changing it to a new one. As you will notice in the UpDateStore method I create a &quot;new&quot; reference object not using an existing one. Assign the entity key to the new reference object, then assign the new reference object to the object I am updating. 

You cannot take an existing entity key and update it to a new one. It is violating a constraint on your database table hence your entity model definition. So use a new object. 

Please post more code to verify what exactly you are doing. TTYL</description>
		<content:encoded><![CDATA[<p>I would have to see more of the code. But I will make some assumptions based on what you have posted. </p>
<p>oldRef.EntityKey = newRef.EntityKey;</p>
<p>Looks like you are taking an old entity key and changing it to a new one. As you will notice in the UpDateStore method I create a &#8220;new&#8221; reference object not using an existing one. Assign the entity key to the new reference object, then assign the new reference object to the object I am updating. </p>
<p>You cannot take an existing entity key and update it to a new one. It is violating a constraint on your database table hence your entity model definition. So use a new object. </p>
<p>Please post more code to verify what exactly you are doing. TTYL</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on .Net Entity Framework Updating Objects in N-Tier Environment by dan</title>
		<link>http://ontehfritz.wordpress.com/2008/11/21/net-entity-framework-updating-objects-in-n-tier-environment/#comment-9</link>
		<dc:creator>dan</dc:creator>
		<pubDate>Wed, 13 May 2009 14:02:27 +0000</pubDate>
		<guid isPermaLink="false">http://ontehfritz.wordpress.com/?p=20#comment-9</guid>
		<description>Thank you for your solution, tht&#039;s exactly what I need.
Could you tell me why I get an exception while executing the following:
oldRef.EntityKey = newRef.EntityKey;  

the exception is:
A referential integrity constraint violation occurred: A property that is a part of referential integrity constraint cannot be changed when the object has a non-temporary key.</description>
		<content:encoded><![CDATA[<p>Thank you for your solution, tht&#8217;s exactly what I need.<br />
Could you tell me why I get an exception while executing the following:<br />
oldRef.EntityKey = newRef.EntityKey;  </p>
<p>the exception is:<br />
A referential integrity constraint violation occurred: A property that is a part of referential integrity constraint cannot be changed when the object has a non-temporary key.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Django Forms &#8211; ChoiceField and MultipleChoiceField by Martin</title>
		<link>http://ontehfritz.wordpress.com/2009/02/15/django-forms-choicefield-and-multiplechoicefield/#comment-7</link>
		<dc:creator>Martin</dc:creator>
		<pubDate>Mon, 20 Apr 2009 16:17:40 +0000</pubDate>
		<guid isPermaLink="false">http://ontehfritz.wordpress.com/?p=61#comment-7</guid>
		<description>Hi Fritz,

I would love to see some example code on how to handle the submission in a view! 

Cheers...</description>
		<content:encoded><![CDATA[<p>Hi Fritz,</p>
<p>I would love to see some example code on how to handle the submission in a view! </p>
<p>Cheers&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Django awesome web framework! by James Mowery</title>
		<link>http://ontehfritz.wordpress.com/2009/02/02/django-awesome-web-framework/#comment-6</link>
		<dc:creator>James Mowery</dc:creator>
		<pubDate>Fri, 06 Feb 2009 23:14:37 +0000</pubDate>
		<guid isPermaLink="false">http://ontehfritz.wordpress.com/?p=57#comment-6</guid>
		<description>I really like the Django framework as well. This coming from someone who was previously not experienced with (much) programming. I knew a bit of PHP and basic concepts of OOP, but that was about it. I took to learning Python and Django fairly fast. Been spending the past two months working on a big Web site project, and it has been coming along very well. I still have to learn plenty more about the framework and the language, but I have been satisfied with the results so far.</description>
		<content:encoded><![CDATA[<p>I really like the Django framework as well. This coming from someone who was previously not experienced with (much) programming. I knew a bit of PHP and basic concepts of OOP, but that was about it. I took to learning Python and Django fairly fast. Been spending the past two months working on a big Web site project, and it has been coming along very well. I still have to learn plenty more about the framework and the language, but I have been satisfied with the results so far.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on .Net Entity Framework Updating Objects in N-Tier Environment by Jeff</title>
		<link>http://ontehfritz.wordpress.com/2008/11/21/net-entity-framework-updating-objects-in-n-tier-environment/#comment-5</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Wed, 21 Jan 2009 03:07:12 +0000</pubDate>
		<guid isPermaLink="false">http://ontehfritz.wordpress.com/?p=20#comment-5</guid>
		<description>Thanks! Gave me Lots of good ideas!</description>
		<content:encoded><![CDATA[<p>Thanks! Gave me Lots of good ideas!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
