The Big Programming Thread - Page 698
Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
WarSame
Canada1950 Posts
| ||
Ropid
Germany3557 Posts
| ||
Deleted User 3420
24492 Posts
edit: It seems I will struggle for hours, then come here and make a post about it, and then instantly figure out my problem. Leaving this here though because I am still curious if anyone here uses django. | ||
aksfjh
United States4853 Posts
I am tryinh to find a file or collection of files. I am given the fully qualified path as 2 different variables, a file and a path. Each may or may not be a regex pattern, but if it is, it is stated that it is. In looking for this file, I am only allowed to use literal characters (no wildcards, pattern matching, or regex) to query directory contents and file existence. example sets (in xml):
Doing the first 3 are easy. You look for the literal file, list out the directories those files are in, and collect all matches to the directory pattern for the results. You do the opposite for the directory, listing all the files in the literal directory and collect all matches to the file pattern for the results. It's the last one that trips me up. The only solution I can think of is breaking the directory regex into as many explicit directories as possible and crawling through the remaining directories for regex matches to further directories and files, but it seems very, very inelegant (and difficult to implement). | ||
Prillan
Sweden350 Posts
On January 04 2016 23:42 WarSame wrote: Whenever you want to use a variable you must declare it in a strongly typed language. This means that if your variable is already in use when you try to declare it you should get a duplicate error. In weakly typed languages, because there's no declaration, you can override the variable without realizing it, which makes it more dangerous. It doesn't have anything to do with "weak" or "strong" types. Is python a strongly typed language? x = 1 Is Haskell a weakly typed language? f x = let x = 2 in x | ||
WarSame
Canada1950 Posts
| ||
Manit0u
Poland17187 Posts
On January 05 2016 02:28 travis wrote: Do any of you use django? I know a bunch of you are web developers. There is something in particular that should be easy that I am just not grasping, but if no one uses django I won't bother. edit: It seems I will struggle for hours, then come here and make a post about it, and then instantly figure out my problem. Leaving this here though because I am still curious if anyone here uses django. I'm not using Django but I have some vague knowledge about it. Is your problem Django-specific or webdev-specific? (or something else entirely) | ||
Nesserev
Belgium2760 Posts
| ||
Deleted User 3420
24492 Posts
Is this understanding correct templates - your html files or whatever, but can contain variables/django code to be loaded into the browser views - the actual code that is ran forms - html forms to be used/reused? models - (this is the confusing part to me... it's how you save/load data from the database??? but are they also forms??) I've got it running, created a template that loads a form which is a textarea and a submit button. then my view takes the cleaned_data, which I seem to be able to print out - but I don't understand how to save this to my database. I understand that model forms have a .save() method but what if I don't want to use a model form? I want to use my own creation. So I don't understand how to take that data and save it to a model. I actually don't even really understand what a model form is - is it just a pre-created form that has a model to go with it already? So in short, how do I use my form/model to save my information to the database? All I want to do is save a string to my database. | ||
Manit0u
Poland17187 Posts
Now, this model will automatically create the database table for you in the database when you migrate (or however else you set schema in Django, I don't remember). On to the forms!
Now, you can render this form by passing it to the view:
If you want to edit the message instead of creating a new one:
Tada! You have just generated a form with text which was saved to the database previously. Also, whenever you first create a message it gets timestamped, the same's true for each edit. So, in short: Your model maps the database. You can build forms based on your model and those forms are submitted to the database. For edition you fetch data from the database (via model) and feed it into the form being generated so that respective fields are auto-filled with data from the database. There you have it all, better explained too: https://docs.djangoproject.com/en/1.9/topics/forms/modelforms/ You really need to read up on MVC architecture... | ||
Deleted User 3420
24492 Posts
I think part of what confuses me with django is just that there is so much stuff... and there seems to be a million ways to do what ends up essentially being the same thing. So if I want to make a form that is based on a model then I need to make it as a ModelForm and describe what it does with the meta class. But there is a meta class for both the models and for the model form? Also I noticed examples with more than one model. I find that kind of strange. When you migrate in django is that essentially django "reorganizing" your database file to work with your models? (I am completely guessing here, how databases work is a mystery to me) Anyways, I will read up now, I promise ![]() | ||
Manit0u
Poland17187 Posts
http://www.sitepoint.com/web-site-basics-beginners/ https://developer.mozilla.org/en-US/docs/Web/Guide/Introduction_to_Web_development http://coding-geek.com/how-databases-work/ http://code.tutsplus.com/tutorials/mvc-for-noobs--net-10488 https://developer.chrome.com/apps/app_frameworks (it's about JS but general concepts stay the same) Edit: Also, if you really want to learn Django properly, please get this book: http://shop.oreilly.com/product/0636920029533.do It's amazing. | ||
Deleted User 3420
24492 Posts
but I just wanted to get your example working and actually save something to a database django was giving me some problems, i deleted my migrations folder, i did make migrations over again, and then did migrate things seemed to go fine my page loads but then when I try to use my form and submit the information to be saved into the database I get: "OperationalError at /home/ no such table: projectApp_message" to try to put it into the database I am using form.save() | ||
Manit0u
Poland17187 Posts
Have you read this yet? https://docs.djangoproject.com/en/1.9/intro/tutorial02/ Also, I haven't done a lot in Django yet so I'm not really that proficient at identifying problems at a glance and knowing the solutions to them. From your error it seems that for some reason migrate didn't create appropriate tables in your database. The only way to know for sure would be checking your database to see if everything is there and it's named correctly (for sqlite you could use something like that: http://sqlitebrowser.org/). | ||
Deleted User 3420
24492 Posts
I was hoping the problem would be some obvious step I missed, but I am suspecting that isn't the case and there is something else going on. So it's okay, I am going to choose not to worry about it. Going to finish dive into python and then I am starting that test driven development book. I glanced at it and it looks pretty fun. edit: just out of curiosity I did look at my database.. it had old tables in it. I deleted it, and made a new database file. Then it worked. So, while I don't understand why I had to remake it, it worked. so yay ! | ||
Manit0u
Poland17187 Posts
| ||
Manit0u
Poland17187 Posts
Why?! T_T | ||
solidbebe
Netherlands4921 Posts
| ||
Deleted User 101379
4849 Posts
On January 06 2016 03:24 Manit0u wrote:
Why?! T_T It's actually not too uncommon. It's a quick way to turn an object tree into an array. It's not exceptionally fast and it really should be in some properly named function somewhere, but the code in itself isn't bad. | ||
aksfjh
United States4853 Posts
On January 06 2016 05:19 Morfildur wrote: It's actually not too uncommon. It's a quick way to turn an object tree into an array. It's not exceptionally fast and it really should be in some properly named function somewhere, but the code in itself isn't bad. Depends on your definition of "bad." It works, but I know some devs that would skewer you for that. | ||
| ||