{"id":302,"date":"2017-08-30T09:00:16","date_gmt":"2017-08-30T00:00:16","guid":{"rendered":"https:\/\/t-office.blue\/?p=302"},"modified":"2017-11-10T05:52:53","modified_gmt":"2017-11-09T20:52:53","slug":"django%e3%81%a7%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e3%81%ab%e5%88%9d%e6%9c%9f%e5%80%a4%e3%82%92%e5%85%a5%e3%82%8c%e3%82%8bfixtures%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/wp.t-office.blue\/?p=302","title":{"rendered":"django\u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u521d\u671f\u5024\u3092\u5165\u308c\u308b(fixtures)\u65b9\u6cd5"},"content":{"rendered":"<h1>django\u3067fixtue<\/h1>\n<p>python\u306e\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30afdjango\u3067\u30a2\u30d7\u30ea\u3092\u4f5c\u6210\u4e2d\u3067\u3001\u305d\u306e\u3068\u304d\u306b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u304b\u3093\u305f\u3093\u306b\u5165\u308c\u305f\u3044\u3068\u601d\u3044RoR\u3067\u3082\u3042\u3063\u305fseed\u3068\u304bfixture\u3068\u304b\u8a00\u3046\u306e\u304c\u3001django\u306b\u3082\u306a\u3044\u304b\u3068\u601d\u3044\u8abf\u3079\u305f\u3089\u3042\u308b\u3068\u3044\u3046\u3053\u3068\u306a\u306e\u3067\u3084\u3063\u3066\u307f\u305f\u3002<\/p>\n<h2>\u6d41\u308c<\/h2>\n<ul>\n<li>fixtures\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u4f5c\u6210<\/li>\n<li>fixture\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210(seed.json)<\/li>\n<li>model\u306e\u524a\u9664<\/li>\n<li>\u30c7\u30fc\u30bf\u8aad\u307f\u8fbc\u307f<\/li>\n<\/ul>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\"\n     style=\"display:block\"\n     data-ad-format=\"fluid\"\n     data-ad-layout-key=\"-ei+6a+g-c3+k8\"\n     data-ad-client=\"ca-pub-4003048870046052\"\n     data-ad-slot=\"1589408991\"><\/ins><\/p>\n<p><script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h3>fixtures\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u4f5c\u6210<\/h3>\n<p>\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u3069\u306e\u3088\u3046\u306b\u8a2d\u7f6e\u3059\u308b\u306e\u304b\u3068\u3044\u3046\u3053\u3068\u3060\u304c,\u30d7\u30ed\u30b8\u30a7\u30af\u30c8<code>$ django-admin startproject mysite<\/code> \u306e\u4e2d\u306b\u4f5c\u3063\u305f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3<code>$ python manage.py startapp polls<\/code>\u306e\u4e2d\u306bfixtures\u3068\u3044\u3046\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u4e2d\u306b[\u30d5\u30a1\u30a4\u30eb\u540d.json]\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\n<h3>fixtue\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210(seed.json)<\/h3>\n<p>\u5148\u306b\u884c\u3063\u3066\u304a\u304f\u3068\u6700\u521dyaml\u3067\u30c7\u30fc\u30bf\u3092\u4f5c\u3063\u305f\u3051\u3069\u539f\u56e0\u4e0d\u660e\u306e\u30a8\u30e9\u30fc\u304c\u51fa\u3066\u4f7f\u3048\u306a\u304b\u3063\u305f\u306e\u3067json\u3092\u4f7f\u3046\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306amodel.py\u3092\u4f5c\u3063\u3066\u3044\u305f\u3068\u3057\u3066<\/p>\n<p>[code lang=python]<br \/>\n# app\/info\/model.py<br \/>\nfrom django.db import models<\/p>\n<p># Create your models here.<\/p>\n<p>class Info(models.Model):<br \/>\nname = models.CharField(&#039;\u540d\u524d&#039;,max_length=30)<br \/>\ndate = models.DateField(auto_now=False)<\/p>\n<p>[\/code]<\/p>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306ajson\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002(\u50d5\u306fseed.json\u3068\u3057\u307e\u3057\u305f\u3002)<\/p>\n<p>[code lang=text]<br \/>\n#app\/info\/fixtures\/seed.json<br \/>\n[<br \/>\n{<br \/>\n&quot;model&quot;: &quot;app.info&quot;,<br \/>\n&quot;pk&quot;: 1,<br \/>\n&quot;fields&quot;:{<br \/>\n&quot;name&quot;: &quot;\u30e6\u30fc\u30b6\uff11&quot;,<br \/>\n&quot;date&quot;: &quot;2017-04-01&quot;<br \/>\n}<br \/>\n},<br \/>\n{<br \/>\n&quot;model&quot;: &quot;app.info&quot;,<br \/>\n&quot;pk&quot;: 2,<br \/>\n&quot;fields&quot;:{<br \/>\n&quot;name&quot;: &quot;\u30e6\u30fc\u30b6\uff12&quot;,<br \/>\n&quot;date&quot;: &quot;2017-04-01&quot;<br \/>\n}<br \/>\n}<br \/>\n]<br \/>\n[\/code]<\/p>\n<h3>model\u306e\u524a\u9664<\/h3>\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u524a\u9664\u3057\u307e\u3059\u3002\uff08\u30e6\u30fc\u30b6\u3068\u304b\u3082\u3059\u3079\u3066\u524a\u9664\u3055\u308c\u307e\u3059\u306e\u3067\u6ce8\u610f)<\/p>\n<p>[code lang=text]<br \/>\n$ python manage.py flush &#8211;database=default<br \/>\n[\/code]<\/p>\n<p>\u3053\u3053\u3067\u6307\u5b9a\u3055\u308c\u3066\u3044\u308b&#8211;database=default\u306f(app\/app\/settings.py)\u306eDATABASES\u306e\u3068\u3053\u308d\u306b\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b&#8217;default&#8217;\u306e\u3053\u3068\u3092\u8a00\u3063\u3066\u308b\u306e\u3067\u3001\u305d\u308c\u305e\u308c\u9055\u3046\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u308c\u3070\u305d\u308c\u306b\u8aad\u307f\u66ff\u3048\u308b\u3002<\/p>\n<h3>\u30c7\u30fc\u30bf\u8aad\u307f\u8fbc\u307f<\/h3>\n<h4>\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3<\/h4>\n<p>[code lang=text]<br \/>\n$ python manage.py makemigrations<br \/>\n$ python manage.py migrate<br \/>\n[\/code]<\/p>\n<h4>\u7ba1\u7406\u30e6\u30fc\u30b6\u4f5c\u6210<\/h4>\n<p>[code lang=text]<br \/>\n$ python manage.py createsuperuser<br \/>\n[\/code]<\/p>\n<h4>fixture\u3088\u308a\u30c7\u30fc\u30bf\u767b\u9332<\/h4>\n<p>[code lang=text]<br \/>\n$ python manage.py loaddata seed<br \/>\n[\/code]<\/p>\n<p>\u203b\u62e1\u5f35\u5b50\u306f\u4e0d\u8981\u3067\u3059(seed.json -&gt; seed)\u00df<\/p>\n<h3>\u53c2\u8003<\/h3>\n<p>http:\/\/buzzlog.hatenablog.com\/entry\/2017\/02\/05\/182535<br \/>\nhttp:\/\/programmer-jobs.blogspot.jp\/2015\/03\/django-python-manage-py-flush-database.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>django\u3067fixtue python\u306e\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30afdjango\u3067\u30a2\u30d7\u30ea\u3092\u4f5c\u6210\u4e2d\u3067\u3001\u305d\u306e\u3068\u304d\u306b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u304b\u3093\u305f\u3093\u306b\u5165\u308c\u305f\u3044\u3068\u601d\u3044RoR\u3067\u3082\u3042\u3063\u305fseed\u3068\u304bfixture\u3068\u304b\u8a00\u3046\u306e\u304c\u3001django\u306b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34,33,5],"tags":[],"class_list":["post-302","post","type-post","status-publish","format-standard","hentry","category-django","category-python","category-5"],"_links":{"self":[{"href":"https:\/\/wp.t-office.blue\/index.php?rest_route=\/wp\/v2\/posts\/302","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.t-office.blue\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.t-office.blue\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.t-office.blue\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.t-office.blue\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=302"}],"version-history":[{"count":18,"href":"https:\/\/wp.t-office.blue\/index.php?rest_route=\/wp\/v2\/posts\/302\/revisions"}],"predecessor-version":[{"id":323,"href":"https:\/\/wp.t-office.blue\/index.php?rest_route=\/wp\/v2\/posts\/302\/revisions\/323"}],"wp:attachment":[{"href":"https:\/\/wp.t-office.blue\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.t-office.blue\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.t-office.blue\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}